/*Jquery Standard Library

Version: 1.0
Date Created: 21/04/08
Author: Ritchie Anesco
Comments: Jquery Framework requred

---------------------------------------------------------------------------*/



//SUBSCRIPTION SCRIPT
jQuery.fn.blindToggle = function(speed, easing, callback) {
	var h = 0;
	var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));
	return this.animate({marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h}, speed, easing, callback);
};

//jQuery.fn.blindToggle = function(speed, easing, callback) {
//	var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom')) + 100;
//	return this.animate({marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h}, speed, easing, callback);
//};


//Add outer div for inner div to slide up and hide	
function login() {
	
	$("#client-form").addClass("reposition");
	var $box = $('#client-form').wrap('<div id="box-outer"></div>');	
	$box.blindToggle();
	
	
	$('#login-toggle a').click(function() {
	    $('#client-form').show();
		var validator = $("#login").validate();
		validator.resetForm();	
		$box.blindToggle(400);
		return false;
	 });
	
}



function showSection(id, hideitems) {
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++) {
		if (divs[i].className.indexOf(hideitems) == -1) continue;
		if (divs[i].getAttribute("id") != id) {
			$(divs[i]).hide();
		} else {
			$(divs[i]).fadeIn('slow');
		}
	}
}


//find id on click and send to showSection function
function showHideNav(list, hideitems) {	
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById(list)) return false;
	var nav = document.getElementById(list);
	var links = nav.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		var sectionId = links[i].getAttribute("href").split("#")[1];
		if (!document.getElementById(sectionId)) continue;
		document.getElementById(sectionId).style.display = "none";
		links[i].destination = sectionId;
		links[i].onclick = function() {
			showSection(this.destination,hideitems);
			return false;
		}
	}
}


//Change widths on affiliate containers
function columnHeight() {

	var maincontent_height = $('#main-content').height(); 
	var subcontent_height = $('#sub-content').height(); 

	if(maincontent_height < subcontent_height) { 
		$('.box-container .middle').height((subcontent_height-20) + "px"); 
	} 
	else if(maincontent_height > subcontent_height) { 
		$('#swf-holder').height((maincontent_height-200) + "px"); 
	}
	
	
}


$(document).ready( function() {
							
    
	//popup window
	$("a.popup").click( function() {
        window.open( $(this).attr('href'), "popup", "width=860, height=670" );
        return false;
    });


	//external link
	$("a.external").click( function() {
        this.target = "_blank";
    });
	
	
	//print
	$("p.print").click( function() {
		if (window.print) window.print();
		else if (VBS) printIt();
		else alert('This script does not work in your browser');
		return false;

	});
	
	
	//back
	$("p.back").click( function() {
		window.back()
		return false;
    });
	
	
	//bookmark
	$("a.bookmark").click( function() {
		bookmark(this.getAttribute("href"), this.getAttribute("title"));
		return false;
    });
		
	
	//Alternative Striped Tables  
	$('table.alternative tbody tr:not([th]):odd').addClass('odd');
 	$('table.alternative tbody tr:not([th]):even').addClass('even');	
	
	
	login();
		
	
	showHideNav("state","state");
	//$('#nsw').show();
	
	
	$("#login").validate({		
		rules: {
			user: "required",
			password: "required"
			},
		messages: {
			user: "Please enter your username"	,
			password: "Please enter your password"
		}
	});

	$("#productSearch").validate({		
		rules: {
			productSearch: "required"
			},
		messages: {
			productSearch: "Please enter your keyword"
		}
	});
	
	
	//Garment List
	
	$(".list").mouseover( function() {
		$(this).addClass("over");
	});
	
	$(".list").mouseout(function() {
		$(this).removeClass("over");
	 });
	
	$(".list").click( function() {
		var links = $(this).find("a").attr("href");
		window.location = links;
		//alert(links);
	});


	
});




