/* Dropdown menu functionaltiy */
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function ddown_open()
{  
   ddown_canceltimer();
   ddown_close();
   css_obj = {'visibility': 'visible',
   			'z-index' : '1'};
   ddmenuitem = $(this).find('ul').css(css_obj);
   
}

function ddown_close()
{  
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function ddown_timer()
{  
closetimer = window.setTimeout(ddown_close, timeout);
}

function ddown_canceltimer()
{  
	if(closetimer) {  
	window.clearTimeout(closetimer);
      closetimer = null;
	}
}

$(document).ready(function()
{  $("#ddown > li").bind('mouseover', ddown_open)
   $("#ddown > li").bind('mouseout',  ddown_timer)}
);

document.onclick = ddown_close;

/* Top Scrolling Banner */
function topScrollingBanner(){
	
	$("#order_online_txt li:visible").fadeOut(500,function(){
		if($(this).next(":hidden").size() == 0) {
			$("#order_online_txt li:first-child").fadeIn(500);
		} else {
			$(this).next(":hidden").fadeIn(500);
		}
		
		setTimeout('topScrollingBanner()', 5000);												  
	});
	
	
}

/* Top Scrolling Banner */


function imageCarousel(){
	
	$(".ImageCarousel li:visible").fadeOut(500,function(){
		if($(this).next(":hidden").size() == 0) {
			$(".ImageCarousel li:first-child").fadeIn(500);
		} else {
			$(this).next(":hidden").fadeIn(500);
		}
		
		setTimeout('imageCarousel()', 5000);												  
	});
	
	
}

/* End Dropdown menu functionaltiy */

$(document).ready(function(){
						   
						   
	
	
	$.ajax({
   			type: "GET",
			cache: false,
   			url: "/ecom/ssi_rotating_header_text.php",
   			success: function(resulthtml){
				$("#order_online_txt").html(resulthtml);
				
				setTimeout('topScrollingBanner()', 5000);
   			}
 	});
	
	// Uncomment this to add back the rotating homepage images
	setTimeout('imageCarousel()', 5000);

	/* Make Enter Keyword dissaper when a person focuses on the box */
	$(".search_input #q").focus(function(){
		if ($(this).val() == "Enter Keyword") {
			$(this).val("");
		}
	});
	
	/* Myspace / YouTube are not set up yet, so trigger a coming soon alert */
	$(".myspace").click(function(event){
		event.preventDefault();
		alert("Coming soon!");
	});
	$(".youtube").click(function(event){
		event.preventDefault();
		alert("Coming soon!");
	});
	
	/* Header search form */
	$("#product_header_submit").click(function(event){
		event.preventDefault();
		$("#product_header_search").submit();
	});
	$("#newsletter_signup a").click(function(event){
		event.preventDefault();
		$("#newsletter_signup_form").submit();
	});
	
	
	
	/* Social media icons hover */
	/*
	$(".social_media_icons a").hover(function(){
		icon = $(this).css("background-image");
		newicon = icon.replace(/.gif/i,"-color.gif");
		$(this).css("background-image",newicon);
	},function(){
		icon = $(this).css("background-image");
		newicon = icon.replace(/-color.gif/i,".gif");
		$(this).css("background-image",newicon);
	});
	*/
});