// General JavaScript Document for The Just Group Site

//jQuery
$(function(){
	
	//Page hierarchy for active menu/nav items
	var section = $('body').attr("id");
	var page = $('body').attr("class");
	$(".header .menu ."+section).addClass("active");
	$(".footer .menu ."+page).addClass("active");
	$("ul.nav ."+page).addClass("active");
	
	//header banner
	$(".banner div").addClass(section);
	if( section != "home" ) { $(".banner").show(); }
	
	//hide all sub nav's
	$("ul.nav ul li > ul").each(function(){
		$(this).hide();
		$(this).prev("a").css({ background:"url(../img/misc/arrow.gif) no-repeat 0 0.4em" });
		$(this).prev("a").hover(
		  function () {
			$(this).css({ background:"url(../img/misc/black_square.gif) no-repeat 0 0.5em" });
		  },
		  function () {
			$(this).css({ background:"url(../img/misc/arrow.gif) no-repeat 0 0.4em" });
		  }
		);
	});
	//show nav which is child of the active link
	$("ul.nav .active ~ ul").each(function(){
		$(this).show("slow");
		$(this).parent().css({ background:"url(../img/misc/dot.gif) repeat-x 0 1.55em" });
		$("ul.nav li:first").css({ background:"none" });
	});
	//show nav which contains active link
	$("ul.nav .active").each(function(){
		$(this).parent().parent().show();
		$(this).parent("li").parent("ul").parent("li").css({ background:"url(../img/misc/dot.gif) repeat-x 0 1.55em" });
		$("ul.nav li:first").css({ background:"none" });
	});

	//table stripes
	$("tbody tr:odd").addClass("stripe");
	
	//PDF links
	$("a[href$='.pdf']").attr("target","_blank");
	$("a[href$='.pdf']").addClass("pdf");
	
	//login popup link
	$("a.login").attr("title","Launch in Pop-up window");
	$("a.login").click(function () { 
	  launchWindow($(this).attr("href"),750,500);
	  return false;
	});
	//regular popup
	$("a.popup").click(function () {
	  launchWindow($(this).attr("href"),750,500);
	  return false;
	});
	//new window
	$("a.newwindow").attr("target","_blank");

	//homepage brand image slideshow
	showBrandImage();
	
});

//homepage brand image slideshow
var fadeSpeed = 1200;
var transitionSpeed = 6000;
var brands = [ "justjeans", "jayjays", "jacquie", "peteralexander", "portmans", "dotti", "smiggle" ];
function showBrandImage() {
	var randBrand = brands[Math.floor(Math.random()*brands.length)];
	$("img.brand").hide();
	$("img.brand").attr( "src", "../img/brands/"+randBrand+".jpg");
	$("img.brand").parent().attr( "href", "http://www."+randBrand+".com.au");
	$("img.brand").attr( "title", "www."+randBrand+".com.au");
	$("img.brand").fadeIn(fadeSpeed);
	$("img.logo").hide();
	$("img.logo").attr( "src", "../img/brands/logo_"+randBrand+".gif");
	$("img.logo").parent().attr( "href", "http://www."+randBrand+".com.au");
	$("img.logo").attr( "title", "www."+randBrand+".com.au");
	$("img.logo").fadeIn(fadeSpeed);
	setTimeout("hideBrandImage()",transitionSpeed);
}
function hideBrandImage() {
	$("img.brand").fadeOut(fadeSpeed, showBrandImage);
	$("img.logo").fadeOut(fadeSpeed);
}


//popup window
function launchWindow( sURL, Width, Height ) {
	var WinLeft = (screen.width - Width)/2;
	var WinTop = (screen.height - Height)/2;
	var oWindow = window.open( sURL, 'apply', ('width=' + Width + ', height=' + Height + ', resizable=yes, scrollbars=yes, menubar=no, status=yes, top=' + WinTop + ', left=' + WinLeft ));
	//setTimeout('oWindow.focus();',250);
}





