// JavaScript Document

/* avoid conflicts with other libraries by redefining jQuery's $() function */
$jq = jQuery.noConflict();

var NHTSA = {};

NHTSA.vars = {
	animspeed:500
};

NHTSA.functions = {};

 // * homepage slideshow large
//  $jq('#hpSlides').append('<div class="c-tl">&nbsp;<\/div><div class="c-tr">&nbsp;<\/div><div class="c-bl">&nbsp;<\/div><div class="c-br">&nbsp;<\/div>');
  $jq('#hpSlides div.slides').cycle(
    {
      fx:'fade',
      timeout:6000,
      speed:500,
      next:'#hpSlides a.next',
      prev:'#hpSlides a.prev',
      pager:'#hpSlides div.ctrl span.pag'
    }
  );
  $jq('#hpSlides div.ctrl a.pause').toggle(
    function(){
      // pause it
      $jq('#hpSlides div.slides').cycle('pause');
      $jq(this).addClass('play');
    },
    function(){
      // restart it
      $jq('#hpSlides div.slides').cycle('resume');
      $jq(this).removeClass('play');
    }
  );
//});


 // * homepage slideshow small
  //$jq('#smallslides').append('<div class="c-tl">&nbsp;<\/div><div class="c-tr">&nbsp;<\/div><div class="c-bl">&nbsp;<\/div><div class="c-br">&nbsp;<\/div>');
  $jq('#smallslides div.slides').cycle(
    {
      fx:'fade',
      timeout:0,
      speed:500,
      next:'#smallslides a.next',
      prev:'#smallslides a.prev',
      pager:'#smallslides div.ctrl span.pag'
    }
  );
  $jq('#smallslides div.ctrl a.pause').toggle(
    function(){
      // pause it
      $jq('#smallslides div.slides').cycle('pause');
      $jq(this).addClass('play');
    },
    function(){
      // restart it
      $jq('#smallslides div.slides').cycle('resume');
      $jq(this).removeClass('play');
    }
  );
//});


// USED with EMAIL safercar

<!--
function popitup(url) {
	newwindow=window.open(url,'name','height=425,width=525,top=300,left=600');
/*if (window.focus) {newwindow.focus()}
	return true;*/
}

//media library

function mediapop(url) {
	newwindow=window.open(url,'name','height=575,width=675,top=300,left=600,resizable');
	/*if (window.focus) {newwindow.focus()}
	return true;*/
}


//another open windos

var popWin = "";

	function openwin(url, strWidth, strHeight) {
	if (popWin != "") {popWin.close()}
	leftStr = (screen.width-strWidth)/2;
	topStr = (screen.height-strHeight)/2-50;
	windowProperties = "toolbar=no,menubar=no,scrollbars=no,statusbar=no,height="+strHeight+",width="+strWidth+",left="+leftStr+",top="+topStr+"";
	popWin = window.open(url,'newWin',windowProperties);
	}


//used for find a recall list box homepage

function buildURL(){
	
	var url	= "http://www-odi.nhtsa.dot.gov/cars/problems/recalls/recallsearch.cfm?type=";
	var args = "&SearchType=DrillDown&step=2";
		
	if(document.getElementById('recall_type').value == "CAMPAIGN_ID"){
		url = "http://www-odi.nhtsa.dot.gov/cars/problems/recalls/recallsearch.cfm";
		document.recall.action = url;
		document.submit();
	}
	else if(document.getElementById('recall_type').value == "SINCE_YESTERDAY"){
		var url2 = "http://www-odi.nhtsa.dot.gov/recalls/results.cfm?SearchType=DateSearch&date=";
		var args2 = "&SCR323=true&summary=true";		
		
		var now = new Date(); 
		var month = now.getMonth()+1;
		var day	= now.getDate()-1;
		var year = now.getFullYear();
		
		var yesterday = getYesterday(month, day, year);//month+"/"+day+"/"+year;
				
		document.recall.action = url2 + yesterday + args2;	
		//alert(document.recall.action);
		document.submit();
	}
	else if(document.getElementById('recall_type').value == "THIS_MONTH"){
		var url2 = "http://www-odi.nhtsa.dot.gov/recalls/results.cfm?SearchType=DateSearch&date=";
		var args2 = "&SCR323=false&summary=true";		
		
		var now = new Date(); 
		var month = now.getMonth()+1;
		var day	= "01";
		var year = now.getFullYear();
		
		var yesterday = month+"/"+day+"/"+year;
				
		document.recall.action = url2 + yesterday + args2;	
		//alert(document.recall.action);
		document.submit();
	}
	else if(document.getElementById('recall_type').value == "DEFAULT"){
		url = "http://www-odi.nhtsa.dot.gov/cars/problems/recalls/recallsearch.cfm";
		document.recall.action = url;
		document.submit();
	}
	else if(document.getElementById('recall_type').value == "LAST_MONTH"){
		url = "http://www-odi.nhtsa.dot.gov/cars/problems/recalls/recallmonthlyreports.cfm";
		document.recall.action = url;
		document.submit();
	} else{
		document.getElementById('recall_type');		
		document.recall.action = url + document.getElementById('recall_type').value + args;		
		document.submit();
	}
}

function getYesterday(month, day, year){

	if(day == 0){
		if(month==2 || month==4 || month==6 || month==8 || month==9 || month==11 ){
			day = 31;
			month = month - 1;
			var yesterday = month+"/"+day+"/"+year;
			return yesterday;
		}

		if(month==5 || month==7  || month==10 || month==12){
			day = 30;
			month = month - 1;
			var yesterday = month+"/"+day+"/"+year;
			return yesterday;		
		}

		if(month==3){
			day = 28;
			if(year % 4 == 0){//Leap Year
				day = 29;
			}
			month = month - 1;
			var yesterday = month+"/"+day+"/"+year;
			return yesterday;
		}

		if(month==1){//January first - should become December 31st of previous year
			day = 31;
			month = 12;
			year = year - 1;
			var yesterday = month+"/"+day+"/"+year;
			return yesterday;
		}
	}else{
		var yesterday = month+"/"+day+"/"+year;
		return yesterday;
	}
}


  // * tabs vehicle shoppers home
  $jq('div.tabs_vs').tabs();
  
  
   // * crash section of details page
   $jq('div.tabs_crash').tabs();
   
      // * safety section of details page
   $jq('div.tabs_safety').tabs();
   
         // * media library
   $jq('div.tabs_media').tabs();

   
   
  
  
  // toggle with images -- use with details page expandable

// JavaScript Document

	  var imgCollapse = new Image();
	  var imgExpand = new Image();
	  imgCollapse.src = "/staticfiles/scassets/images/collapse.gif";
	  imgExpand.src = "/staticfiles/scassets/images/expand.gif";
	  
	  function restoreBlock(divId, imgNode){
var oImg = imgNode;

		var oDiv = document.getElementById(divId);
		if (oDiv && oDiv.style.display == "block"){
			oImg.src = imgCollapse.src;
			oDiv.style.display = "none";
		}else{
			oImg.src = imgExpand.src;
			oDiv.style.display = "block";	
		}


  }
	 //toggle with href used with ivog home read more 

  function toggle_visibility(id) {
      var e = document.getElementById(id);
      if(e.style.display == 'block')
         e.style.display = 'none';
      else
         e.style.display = 'block';
   }
//toggle with first use safety details page
 function expandit(id) {
		document.getElementById(id).style.display = 'block';
	}
		function closeit(id) {
		document.getElementById(id).style.display = 'none';
	}
