// JavaScript Document
function openPanel(obj){
	// Need to close all the panels first.
	$(".nav-panel").slideUp("fast");
	
	if ($("#panel-"+obj).is(":hidden")) {
		$("#panel-"+obj).slideDown("slow");
	} else {
		$("#panel-"+obj).slideUp("slow");
	}
}

function openSubPanel(obj){

	// Reset anchors
	$('section#panel-what .titles a').removeClass('active');
	$('section#panel-what #nav-' + obj).addClass('active');
	
	
	// Reset everything;
	$('section#panel-what .slide').css('display', 'none');
	$('section#panel-what #' + obj).css('display', 'block');
	
	// Set the margin out
	$('section#panel-what #' + obj + " .inner").css('margin-left', '-960px');
	
		var $marginLefty = $('section#panel-what #' + obj + " .inner");
		$marginLefty.animate({
		  marginLeft: 0
		},500);
}

function openDownloadsSubPanel(obj){

	// Reset anchors
	$('section#panel-downloads .titles a').removeClass('active');
	$('section#panel-downloads #nav-' + obj).addClass('active');
	$('.paging').css('display', 'none');
	
	// Reset everything;
	$('section#panel-downloads .slide').css('display', 'none');
	$('section#panel-downloads #' + obj).css('display', 'block');
	
	// If it's the brochure need to display the first sldie.
	if (obj == "brochures")
	{
		$('section#panel-downloads div.inner div#b-0').css('display', 'block');
		$('.paging').css('display', 'block');
	}
	// Set the margin out
	$('section#panel-downloads #' + obj + " .inner").css('margin-left', '-960px');
	
		var $marginLefty = $('section#panel-downloads #' + obj + " .inner");
		$marginLefty.animate({
		  marginLeft: 0
		},500);
		
}

var BrochureSlideNumber = 0;

function openBrochureSubPanelNext(dir){

	if(dir == "n")
	{
		if (BrochureSlideNumber == 2)
			return;
		
		BrochureSlideNumber = eval(BrochureSlideNumber + 1);
	}
	else
	{
		if (BrochureSlideNumber == 0)
			return;

		BrochureSlideNumber = eval(BrochureSlideNumber - 1);
	}
	
	obj = "b-" + BrochureSlideNumber;
	
	// Reset everything;
	$('section#panel-downloads article#brochures .slide').css('display', 'none');
	$('section#panel-downloads article#brochures #' + obj).css('display', 'block');

	
	// Set the margin out
	$('section#panel-downloads article#brochures #' + obj + " .inner").css('margin-left', '-960px');
		var $marginLefty = $('section#panel-downloads article#brochures #' + obj + " .inner");
		$marginLefty.animate({
		  marginLeft: 0
		},500);
}

function openBrochureSubPanel(obj){

	// Reset everything;
	$('section#panel-downloads article#brochures .slide').css('display', 'none');
	$('section#panel-downloads article#brochures #' + obj).css('display', 'block');
	
	// Set the margin out
	$('section#panel-downloads article#brochures #' + obj + " .inner").css('margin-left', '-960px');
	
		var $marginLefty = $('section#panel-downloads article#brochures #' + obj + " .inner");
		$marginLefty.animate({
		  marginLeft: 0
		},500);
		
	arr = obj.split("-");
	BrochureSlideNumber = arr[1];
}


function sideMenuAccordian() {	
	
	$('li:has(ul)').children('a').click(function() {	
		$('ul.opened').hide().removeClass('opened'); /// New line																																																				
		$(this).parent('li').children('ul').slideToggle().addClass('opened');
		return false;
	});	
	
	/* the following two lines will ensure that the UL opens to the section that you had open on the navigation when you left the page, if you wish the navigation to simply revert back to all the categories being closed when you leave a page then remove the two lines of code below */
	$('a.on').parent('li').children('ul').show();
	$('a.on').parent('li').parent('ul').show();
	$('ul.children').filter(':visible').addClass('opened');
}


$(document).ready(function($) {
	$('#s').attr('placeholder', 'Search...');
	$( '#s').placeHeld();
	
	// lets move the facts data.
	if ($("div#facts").length > 0){
		$("div.col-middle").html("<div class='facts'>" + $("div#facts").html() + "</div>" + $("div.col-middle").html());
		$("div.content-wrapper div#facts").css("display","none");
	}

	// lets move the Service Champion 
	if ($("div#service-champion").length > 0){
		$("div.col-middle").html("<h3>Service Champion</h3>" + $("div#service-champion").html() + $("div.col-middle").html());
		$("div#service-champion").css("display","none");
	}

	$(".main-nav")
		.click(function() { 
			$(".main-nav").removeClass("active");
			$(this).addClass("active");
		});

    $(".paging img")
		.click(function() { 
		
			// Reset them all
			 //var src = $('.paging img').attr("src").replace("-active.jpg", ".jpg");
            //$('.paging img').attr("src", src);
			
			//var src = $(this).attr("src").match(/[^\.]+/) + "-active.jpg";
			//$(this).attr("src", src);
        })
        .mouseover(function() { 
			
			if ($(this).attr("src").indexOf("-active.jpg") < 0)
			{
	             var src = $(this).attr("src").replace("page.jpg", "page-active.jpg");
    	        $(this).attr("src", src);
			}
        })
        .mouseout(function() {
            var src = $(this).attr("src").replace("page-active.jpg", "page.jpg");
            $(this).attr("src", src);
        });
});
