$(document).ready(function() {
			   
	$(".rollOver img").hover(
		 function()
		 {
		  this.src = this.src.replace("Btn","BtnOver");
		 },
		 function()
		 {
		  this.src = this.src.replace("BtnOver","Btn");
		 }
	);

	$(".single_image").fancybox();

	$('body').supersleight({shim: '/images/x.gif'});

	if(document.location.href.indexOf("#") == -1 || document.location.href.split("#")[1] == 0){
	    showSection('');
	}else{
		showSection(document.location.href.split("#")[1]);
	}
		
	document.getElementById("zipTxt").onkeydown = function (e) {
            e = e || window.event;
            if (e.keyCode === 13) {
                submitForm();
                return false;
            }
        };
		
	$.history.init(callback);
    $("a[rel='history']").click(function(){
        $.history.load(this.href.replace(/^.*#/, ''));
        return false;
    });

});

function callback(hash)
{
    showSection(hash);
}

function submitForm(){
	if(validateZipCode(document.getElementById("zipTxt").value)){
		//make ie6 happy
		setTimeout(redirect, 0 );
	}else{
		alert("Please enter a valid zip code.");	
	}
}

function redirect(){
	window.location.href = "http://stores.lowes.com/lowes/cgi/choose_store?mapid=US&lang=en&design=default&zip="+document.getElementById("zipTxt").value;
}

function submitEmail(){
	document.getElementById('downloadForm').submit();
}

function validateZipCode(elementValue){
    var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
    return zipCodePattern.test(elementValue);
}

function showSection(s){
	var sections = ["sysReq","mainContent1"];

	for(var i=0;i<sections.length;i++){
		if(sections[i] != s){
			$('#'+sections[i]).hide();	
		}else{
			$('#'+sections[i]).show();	
		}
	}
	
	document.location.replace(document.location.href.split("#")[0] + "#"+s);
}

function validateEmail(elementValue){
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(elementValue);
 }

function downloadSoftware(s){
	if(!validateEmail(document.getElementById("emailTxt").value)){
		alert("Please enter a valid email address.");
	}else{
		switch(s){
		case 'mac':
			window.open("software/paintpix_mac_setup.zip",'download');
			break;
		case 'win':
			window.open("software/paintpix_mac_setup.zip",'download');
			break;
		}
		//make ie6 happy
		setTimeout(submitEmail, 0);	
	}
}