$(document).ready(function(){
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Rollovers for images
	
	$nav_on = "news_tour";
	
	function reset_nav(){
		if($nav_on != "news_tour"){
			$('#button_news').attr("src", $('#button_news').attr("src").replace(/_on/, '_off'));
			$('#button_tour').attr("src", $('#button_tour').attr("src").replace(/_on/, '_off'));
		} else {
			$('#button_news').attr("src", $('#button_news').attr("src").replace(/_off/, '_on'));
			$('#button_tour').attr("src", $('#button_tour').attr("src").replace(/_off/, '_on'));
		}
		
		if($nav_on != "media"){
			$('#button_media').attr("src", $('#button_media').attr("src").replace(/_on/, '_off'));
		} else {
			$('#button_media').attr("src", $('#button_media').attr("src").replace(/_off/, '_on'));
		}
		
		if($nav_on != "merch"){
			$('#button_merch').attr("src", $('#button_merch').attr("src").replace(/_on/, '_off'));
		} else {
			$('#button_merch').attr("src", $('#button_merch').attr("src").replace(/_off/, '_on'));
		}
	}
	
	$('.roll').hover(function(){
		//alert($(this).attr("alt"));
		if($(this).attr("alt") != $nav_on){
			$(this).attr("src", $(this).attr("src").replace(/_off/, '_on'));
		}
	},function(){
		if($(this).attr("alt") != $nav_on){
			$(this).attr("src", $(this).attr("src").replace(/_on/, '_off'));
		}
	});
	
	
	$('#button_news').click(function() {
		$('#panels').animate({
			opacity: 1.0,
			left: '0'
		}, 1000, function() {
			$nav_on = "news_tour";
			reset_nav();
		});
	});
	
	$('#button_tour').click(function() {
		$('#panels').animate({
			opacity: 1.0,
			left: '0'
		}, 1000, function() {
			$nav_on = "news_tour";
			reset_nav();
		});
	});
	
	$('#button_media').click(function() {
		$('#panels').animate({
			opacity: 1.0,
			left: '-1000'
		}, 1000, function() {
			$nav_on = "media";
			reset_nav();
		});
	});
	
	$('#button_merch').click(function() {
		$('#panels').animate({
			opacity: 1.0,
			left: '-2000'
		}, 1000, function() {
			$nav_on = "merch";
			reset_nav();
		});
	});
	
/*
	$('#free_digital_download').click(function() {
		$('#panels').animate({
			opacity: 1.0,
			left: '-2000'
		}, 1000, function() {
			$nav_on = "merch";
			reset_nav();
		});
	});
*/	
	$('#close').click(function() {
		$('#overlay').fadeOut(300);
		$('#popup').fadeOut(300);
	});
	
	$('#overlay').click(function() {
		$('#overlay').fadeOut(300);
		$('#popup').fadeOut(300);
	});

	
	$('.photo').click(function() {
		ids = $(this).attr("id");
		
		$.ajax({
			type: "GET",
			url: "http://agreatbigpileofleaves.com/inc/ajax.php",
			data: "type=photo&ids="+ids,
			success: function(msg){
				$('#popup_content').html(msg);
				$('#overlay').fadeIn(300);
				$('#popup').fadeIn(300);
			}
		});
	});
	
	$('.video').click(function() {
		ids = $(this).attr("id");
		
		$.ajax({
			type: "GET",
			url: "http://agreatbigpileofleaves.com/inc/ajax.php",
			data: "type=video&ids="+ids,
			success: function(msg){
				$('#popup_content').html(msg);
				$('#overlay').fadeIn(300);
				$('#popup').fadeIn(300);
			}
		});
	});
	

	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Click to register
	
	$('#add_email').click(function() {
		email = $('#email').val();
		
		check = echeck(email);
		
		if(check){
			$.ajax({
				type: "GET",
				url: "http://agreatbigpileofleaves.com/inc/register.php",
				data: "email="+email,
				success: function(msg){
					$('.download').show(300);
				}
			});
		}
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Search Field Actions
	
	$("#search").focus(function(){	
		if($(this).val() == 'Search'){
			$(this).val('');
		}
	});
	
	$("#search").blur(function(){
		if($(this).val() == ''){
			$(this).val('Search');
		}
	});
	
	$("#search").keydown(function(event){
		if(event.keyCode == 13){
			needle = $(this).val();
			document.location.href='http://domain.com/search/'+needle+'/';
		}
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Toggle Item (FAQ)
	
	$(".question").click(function () {
		$('#answer_'+this.id).slideToggle(200);
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// For slideshow
	
	$('#slideshow').cycle({ 
		timeout: 10000,
		delay:   2000, 
		speed:   2000 
	}); 
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// AJAX Log in
	
	function log_in(){
		username = $('#site_username').val();
		password = $('#site_password').val();
		
		$.ajax({
			type: "POST",
			url: "http://domain.com/inc/login.php",
			data: "username="+username+"&password="+password,
			success: function(msg){
				if(msg == 'success'){
					//window.location="index.php";
					//alert('You have successfully logged in!');
					window.location.reload(true);
				} else {
					alert('Incorrect: Please check your username or password.');
				}
			}
		});
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
});


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

