//PRELOAD IMAGES
var cache = [];
// Arguments are image paths relative to the current page.
function preLoadImages() {
var args_len = arguments.length;
	for (var i = args_len; i--;) {
	  var cacheImage = document.createElement('img');
	  cacheImage.src = arguments[i];
	  cache.push(cacheImage);
	}
}

///////LOCATIONS//////

function getDealerList(location){
	/*
var win = window.location.href;
	window.location.href = win+"#"+location;
*/
	jQuery("#location-display").html(jQuery("#"+location).html());
	//jQuery("#list-"+location).show();
	//locations link whole li
	$(".city-links").click(function(){
		window.location = $(this).find("a").attr("href");
	});
}


function optionImgClick(obj){

	var id =  $(obj).attr("id").split("_")[1];
	
	//remove all
	$(".grp"+id).each(function(){
		$(this).css("border","none");
	});
	//add border
	$(obj).css("border","thin solid black");
	
	var image = "/" + $(obj).attr('src');
	var title = $("#prodTitle"+id).html();
	var type = $(obj).attr('alt');
	var cap = title + " - " + type;
	$("#curLightbox"+id).attr('href', image);
	$("#curLightbox"+id).attr('title', cap);
	Shadowbox.setup("#curLightbox"+id, {
		gallery: "#image1_"+id,
	    title: cap
    });
    
    $("#cur_img"+id).html("<strong>"+$(obj).attr('alt')+"</strong><br /><img src='"+$(obj).attr('src')+"' border='0' width='180' />");
    
    //$("#wish_item"+id).html($(obj).attr('alt'));

	//var filename = $(obj).attr('src').substring($(obj).attr('src').lastIndexOf('/')+1);
	var image = $(obj).attr('id');
    //$("#wish_link"+id).attr('href').substring($("#wish_link"+id).attr('href').lastIndexOf('=')+1);
    var baselink = $("#wish_link"+id).attr('href').split("?")[0];
    $("#wish_link"+id).attr('href',baselink+"?id="+image);

    Shadowbox.setup("#wish_link"+id, {
		gallery: "#wish"+id
    });
}

jQuery(document).ready(function() {

$("table.business-list.news").tablesorter({widthFixed: true, widgets: ['zebra']});
$("#tabs").tabs();
/*$("#accordion").accordion({collapsible: true,active:false});*/


	$("#accordion").accordion({ collapsible: true, autoHeight: false});
	var win = window.location.href;
	var cut = win.split("/");
	var active = 0;
	var check = false;
	//alert(cut);
	
	$("#accordion h3 a").each(function(){
		if(cut[4] == $(this).attr("title")){
			check = true;
			//alert("active: "+active);
			if(active) $("#accordion").accordion( "option", "active", active);
			else $("#accordion").accordion( "option", "active");
		}
		active++;
	});
	
	if(!check) $("#accordion").accordion( "option", "active", false);


///////////DROPDOWN//////////

  $(function() {
    $('.topnav').droppy();
  });

///////////DROPDOWN//////////


//DISABLE RIGHT CLICK

/*
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
  if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
  function mischandler(){
   return false;
 }
  function mousehandler(e){
 	var myevent = (isNS) ? e : event;
 	var eventbutton = (isNS) ? myevent.which : myevent.button;
    if((eventbutton==2)||(eventbutton==3)) return false;
 }
 document.oncontextmenu = mischandler;
 document.onmousedown = mousehandler;
 document.onmouseup = mousehandler;
 
*/
 

var curPage;

// NEWSLETTERS//
jQuery("#prev").click(
	function() {
		var win = window.location.href;
		var new_url = win.split("=");
		curPage = new_url[1];
		
		if(curPage == 1)
		{
			//window.location.href = new_url[0]+"=4";
		}
		else if(curPage == 2)
		{
			window.location.href = new_url[0]+"=1";
		}
		else if(curPage == 3)
		{
			window.location.href = new_url[0]+"=2";
		}
		else if(curPage == 4)
		{
			window.location.href = new_url[0]+"=3";
		}
		else if(curPage == 5)
		{
			window.location.href = new_url[0]+"=4";
		}
		else if(new_url == win)
		{
			//window.location.href = win+"?page=4";
		}
	}
);

jQuery("#next").click(
	function() {
		var win = window.location.href;
		var new_url = win.split("=");
		curPage = new_url[1];
		
		if(curPage == 1)
		{
			window.location.href = new_url[0]+"=2";
		}
		else if(curPage == 2)
		{
			window.location.href = new_url[0]+"=3";
		}
		else if(curPage == 3)
		{
			window.location.href = new_url[0]+"=4";
		}
		else if(curPage == 4)
		{
			window.location.href = new_url[0]+"=5";
		}
		else if(curPage == 5)
		{
			window.location.href = new_url[0]+"=1";
		}
		else if(new_url == win)
		{
			window.location.href = win+"?page=2";
		}
	}
);
 
 
 
 
 
 
 
 
 //EXPAND & COLLAPSE DIVS

var div = jQuery(".main_content").height();
//div -= 105;

var small = true; 
jQuery(".main_content").height(216);
//toggle the component with class main_content

jQuery(".heading").click(function()
{
    if(small == true) {
        jQuery(".main_content").height(div);
        jQuery("#more").html("<img src='/assets/templates/eotr/images/arrow_up.png' width='15' align='left'> Learn More");
        small = false;
    }
    else if(small == false) {
        jQuery(".main_content").height(216);
        jQuery("#more").html("<img src='/assets/templates/eotr/images/arrow_down.png' width='15' align='left'> Learn More")
        small = true;
    }
});

$(".wish-links").click(function(){
	//alert('click');
	var removeLink = $(this).find('.wish-delete-container a').attr('href');
	var time = new Date().getTime();
	$(this).slideUp();
	$.get(removeLink+"&cache="+time, function(data){
   		//alert("Data Loaded: " + data);
   		var wishlist_num = data;
   		$("#wish_num_display").text("Wishlist ("+wishlist_num+") Items.");
   		//alert(wishlist_num);
   		if(wishlist_num == 0) $(".wish-links-nohover").fadeIn();
 	});
});

$(".wish-delete-container a").click(function(){
	var removeLink = $(this).attr('href');
	var time = new Date().getTime();
	var parent = $(this).parent().parent();
	parent.slideUp();
	$.get(removeLink+"&cache="+time, function(data){
   		//alert("Data Loaded: " + data);
   		var wishlist_num = data;
   		$("#wish_num_display").text("Wishlist ("+wishlist_num+") Items.");
   		//alert(wishlist_num);
   		if(wishlist_num == 0) $(".wish-links-nohover").fadeIn();
 	});
	
 	
 	return false;	
	//window.location.href = removeLink;
});

//DROPDOWN NAVIGATION

/*
jQuery("#4").mouseover(function() {	  		
	jQuery('#page_4').show();
});
	   
jQuery("#page_4").mouseout(function() {
	jQuery('#page_4').hide();	
});
*/


jQuery("#4").hover(
  function () {
  	jQuery("#page_4").slideDown(250);
  	$.data(document.body, 'cancelHide', true);
  }, 
  function () {
  	$.data(document.body, 'cancelHide', false);
	setTimeout(function() {
		if (!$.data(document.body, 'cancelHide')) {
			jQuery("#page_4").slideUp(100);
		}
	}, 100);
  }
);

/*
$("div.overout").mouseover(function(){
      $("p:first",this).text("mouse over");
    }).mouseout(function(){
      $("p:first",this).text("mouse out");
      $("p:last",this).text(++i);
    });
*/

jQuery("#page_4").mouseover(function(){
	$.data(document.body, 'cancelHide', true);
});

jQuery("#page_4").mouseout(function(){
	$.data(document.body, 'cancelHide', false);
	setTimeout(function() {
		if (!$.data(document.body, 'cancelHide')) {
			jQuery("#page_4").slideUp(100);
		}
	}, 100);
});

//Colour options

var large = "";
var img;
var first = true;


jQuery(".option").click(function(){
	optionImgClick($(this));
});


var url = window.location.href;

jQuery(".generic_cart").click(function() {
	var id =  $(this).children(":first-child").attr("id");
	
	//var newItem = $("#wish_item"+id).html();
    //var newImg = $("#wish_img"+id).html();
    
/*
    alert(url+"?item="+newItem+"&img="+newImg);
	
	window.location.href = url+"?item="+newItem+"&img="+newImg;
	return false;
*/
/*
	var large = jQuery("#cur_img"+id);
		
		if(large == "" )
		{
		}
		
		else if(large != "")
		{
			var current = jQuery("#cur_img"+id).html();
			//alert(current);
			var item = current.split(">");
			//alert(item);
			var newItem= item[2].split("<");
			//alert(newItem[0]);
			wishlist += newItem[0]+"<br>";
			//large.innerHTML = wishlist;
		
			var im = img.split("/");
			//alert(im[5]);
			var newIm = im[5].split(".");
			//alert(im[5]);
		
			//get page id number
			var new_url = url.split("=");
			
			window.location.href = url+"&item="+newItem[0]+"&img="+newIm[0];
		}
*/
});

/*
jQuery("#cur_img").click(
	function() {

		if(large == "")
		{
		}
	
		else if(large != "")
		{
					//var elem = document.getElementById("image1").style.border="thin solid red";
			large = document.getElementById("cur_img");
			var i = large.innerHTML;
			//window.open(img);
		}
	}
);*/

//add arrow background if element has children
$(".subnav li:has(ul) a").addClass("nav_arrow");
$(".subnav li:not(:has(ul)) a").removeClass("nav_arrow");

//button elements
$("input:submit, input:reset, input:button, button").button();
$("#tourBtn").button({icons: {primary: 'ui-icon-video'}});
$(".quiz_button").button();

});

function PrintThisPage() 
{ 
   var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
       sOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; 

   var sWinHTML = document.getElementById('contentstart').innerHTML; 
   
   var winprint=window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write(sWinHTML);          
       winprint.document.close(); 
       winprint.focus(); 
}
