var domain = "";
$j(document).ready(function(){	
	$j('#skey').alphanumeric({allow:"-"});
	domain = "http://"+document.domain;	
	slideShow();	
	$j("#slider-nav a").bind("click",slideNav);
	$j(".homesc_cont img").bind("click",searchKey);
	$j('#skey').keyup(function(e){
			if(e.keyCode==13) $j(".homesc_cont img").trigger("click");
	});
	$j("div[id='myp-but']").bind("click",doActions);
});
function doActions(){
	var action = $j(this).attr("action");	
	if(action == "login"){
		loginPopD("login");
	}else if(action == "signup"){
		loginPopD("signup");
	}
}
function loginPopD(opttion){		
	$j(".popup-contentbody").html("<iframe id='ordsigfrm' src='"+domain+"/ordersignuplogin.php?svc=search&opt="+opttion+"' frameborder='0' scrolling='no' width='730px' height='265px' ></iframe>");
	showPopDiv();
}
function searchKey(){
	var skey = $j("#skey").val();
	if(skey){
		window.location = domain+"/brands.htm?skey="+skey;		
	}
}
function slideShow() {
	//Set the opacity of all images to 0
	$j('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$j('#gallery a:first').css({opacity: 1.0});	
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);	
}

function gallery() {	
	$j("#slider-nav a").removeClass("active");
	//if no IMGs have the show class, grab the first image
	var current = ($j('#gallery a.show')?  $j('#gallery a.show') : $j('#gallery a:first'));
	
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $j('#gallery a:first') :current.next()) : $j('#gallery a:first'));		
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	$j("#slider-nav a:nth-child("+next.attr("pos")+")").addClass("active");
	
}

function slideNav(){
	$j("#slider-nav a").removeClass("active");
	var nav = $j(this).attr("nav");
	var current = ($j('#gallery a.show')?  $j('#gallery a.show') : $j('#gallery a:first'));
	var next = $j("#gallery a[pos='"+nav+"']");
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	$j("#slider-nav a:nth-child("+nav+")").addClass("active");
}
