$(document).ready(function(){
	
	
	
	
	//////////////////////////////////////////////////////////////////////////////
	// ajax calculate tax
	
	$('#shipping_method').change(function() {
		
		shipping_state 	= $('#shipping_state').val();
		shipping_zip 	= $('#shipping_zip').val();
		shipping_method = $('#shipping_method').val();
		
		$.ajax({
			url: "http://mixedgreens.com/inc/cart_ajax.php?shipping_state="+shipping_state+"&shipping_zip="+shipping_zip+"&shipping_method="+shipping_method,
			success: function(msg){
				$('#total_update').html(msg);
			}
		});
	});
	
	$('#update_totals').click(function() {
		
		shipping_state 	= $('#shipping_state').val();
		shipping_zip 	= $('#shipping_zip').val();
		shipping_method = $('#shipping_method').val();
		
		$.ajax({
			url: "http://mixedgreens.com/inc/cart_ajax.php?shipping_state="+shipping_state+"&shipping_zip="+shipping_zip+"&shipping_method="+shipping_method,
			success: function(msg){
				$('#total_update').html(msg);
			}
		});
		
		return false;
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// For Register Page password masking
	/*
	if($('#register_password').val() == 'PASSWORD'){
		$('#register_password').hide();
	} else {
		$('#register_password_clear').hide();
	}
	
	
	if($('#register_password_confirm').val() == 'CONFIRM PASSWORD'){
		$('#register_password_confirm').hide();
	} else {
		$('#register_password_confirm_clear').hide();
	}
	
	$('#register_password_clear').focus(function() {
		if($('#register_password').val() == 'PASSWORD'){
			$('#register_password_clear').hide();
			$('#register_password').show();
			$('#register_password').val("");
		} else {
			$('#register_password').hide();
			$('#register_password_clear').show();
		}
	});
	
	$('#register_password_confirm_clear').focus(function() {
		if($('#register_password_confirm').val() == 'CONFIRM PASSWORD'){
			$('#register_password_confirm_clear').hide();
			$('#register_password_confirm').show();
			$('#register_password_confirm').val("");
		} else {
			$('#register_password_confirm').hide();
			$('#register_password_confirm_clear').show();
		}
	});
	*/
	
	//////////////////////////////////////////////////////////////////////////////
	// For Blog page years toggle
	
	$(".years").click(function () {
		$('#'+this.id+'_months').slideToggle(200);
		return false;
	});
	
	
	//////////////////////////////////////////////////////////////////////////////
	// For Blog page comment toggle
	
	$(".toggle_blog_comment").click(function () {
		$('#post_'+this.id).slideToggle(200);
		return false;
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// For Staff page bio length toggle
	
	$(".bio_more").click(function () {
		$('#extended_'+this.id).toggle(0);
		if($('#extended_'+this.id).css('display') == "none"){
			$(this).html("MORE &raquo;");
		} else {
			$(this).html("LESS &laquo;");
		}
		return false;
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// For Exhibition page length toggle
	
	$("#current_exhibition2_toggle").click(function () {
		$('#current_exhibition2_extended').toggle(0);
		if($('#current_exhibition2_extended').css('display') == "none"){
			$(this).html("MORE &raquo;");
		} else {
			$(this).html("LESS &laquo;");
		}
		return false;
	});
	
	$("#current_exhibition_toggle").click(function () {
		$('#current_exhibition_extended').toggle(0);
		if($('#current_exhibition_extended').css('display') == "none"){
			$(this).html("MORE &raquo;");
		} else {
			$(this).html("LESS &laquo;");
		}
		return false;
	});
	
	$("#current_installation_toggle").click(function () {
		$('#current_installation_extended').toggle(0);
		if($('#current_installation_extended').css('display') == "none"){
			$(this).html("MORE &raquo;");
		} else {
			$(this).html("LESS &laquo;");
		}
		return false;
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// For header crate toggle
	
	$("#crate_toggle").click(function () {
		
		if($('#crate').css('display') == "none"){
			$('#login').slideUp(100);
			$('#crate').slideDown(100);
			
		} else {
			$('#crate').slideUp(100);
		}
		return false;
	});
	
	$("#crate").bind( "clickoutside", function(event){
		$(this).slideUp(100);
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// For header login toggle
	
	
	$(".open_login").click(function () {
		$('#crate').slideUp(100);
		$('#login').slideDown(100);
		return false;
	});
	
	$("#login_toggle").click(function () {
		
		if($('#login').css('display') == "none"){
			$('#crate').slideUp(100);
			$('#login').slideDown(100);
		} else {
			$('#login').slideUp(100);
		}
		return false;
	});
	
	$("#login").bind( "clickoutside", function(event){
		$(this).slideUp(100);
	});
	
	$("#login_email").focus(function(){	
		if($(this).val() == 'EMAIL'){
			$(this).val('');
		}
	});
	
	$("#login_email").blur(function(){
		if($(this).val() == ''){
			$(this).val('EMAIL');
		}
	});
	
	$("#login_password").focus(function(){	
		if($(this).val() == 'PASSWORD'){
			$(this).val('');
		}
	});
	
	$("#login_password").blur(function(){
		if($(this).val() == ''){
			$(this).val('PASSWORD');
		}
	});

	$("#login_button").click(function () {
		document.login_form.submit();
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// 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://localhost/Thang12/SiteMixedGreens/results.php?q='+needle;
		}
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// Logoff
	
	$("#member_toggle").click(function () {
		logoff();
	});
	
	function logoff(){
		$.ajax({
			url: "http://mixedgreens.com/inc/logoff.php",
			success: function(msg){
				window.location.reload(true);
			}
		});
	}
	
	//////////////////////////////////////////////////////////////////////////////
	// Framing Cost
	
	$("#framing_toggle").click(function () {
		$('#total_price_with_frame').toggle(0);
		$('#total_price_without_frame').toggle(0);
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// For work zoom
	
	$("#alternate_views img").click(function () {
		//$path="http://localhost/Thang1/Mixedgreen_final/";
		$('#main_image').attr('src', $(this).attr('title'));
		$('#zoom_image').attr('src', $(this).attr('title'));
	});
	
	$(".zoom_toggle").click(function () {
		$('#zoom').toggle(0);
		return false;
	});
	
	$("#zoom").bind( "click clickoutside", function(event){
		$(this).fadeOut(200);
	});
	
	//////////////////////////////////////////////////////////////////////////////
	
	/*
	$('.slideshow').cycle({ 
		fx:     'scrollLeft',
		timeout: 0, 
		speed:   300,
		prev:    '.slideshow_prev',
        next:    '.slideshow_next',
        after:     function() {
            $('#caption').html(this.alt);
        }
	});
	*/
	
	$('.slideshow').each(function() {
		var p = this.parentNode;
		$(this).cycle({
			fx:     'scrollLeft',
			speed: 300,
			timeout: 0,
			next: $('.slideshow_next', p),
			prev: $('.slideshow_prev', p),
			after:     function() {
	            $('#caption').html(this.alt);
	        }
		});
	});
	
	//////////////////////////////////////////////////////////////////////////////
	// Toggle for scale on work page
	
	$("#scale_toggle").click(function () {
		$('#scale').toggle(0);
		return false;
	});
	
	$("#scale").bind( "clickoutside", function(event){
		$(this).fadeOut(200);
	});
	
	
	//////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////
	// Cart
	
	$(".add_to_crate").click(function () {
		
		framing = ($('#framing_toggle').attr('checked') == true)? '1' : '0';
		add = $('#type').html()+framing+'-'+this.id;
		
		$.ajax({
			url: "http://mixedgreens.com/inc/cart.php",
			data: "add="+add,
			success: function(msg){
				//alert(msg);
				window.location.reload(true);
			}
		});
	});
	
	$(".remove_from_crate").click(function () {
		
		remove = this.id;
		
		$.ajax({
			url: "http://mixedgreens.com/inc/cart.php",
			data: "remove="+remove,
			success: function(msg){
				//alert(msg);
				window.location.reload(true);
			}
		});
	});

	$("#use_billing_info").click(function () {
		
		$("#shipping_first_name").val( $("#billing_first_name").val() );
		$("#shipping_last_name").val( $("#billing_last_name").val() );
		$("#shipping_address_1").val( $("#billing_address_1").val() );
		$("#shipping_address_2").val( $("#billing_address_2").val() );
		$("#shipping_city").val( $("#billing_city").val() );
		$("#shipping_state").val( $("#billing_state").val() );
		$("#shipping_zip").val( $("#billing_zip").val() );
		
		return false;
		
	});

	//////////////////////////////////////////////////////////////////////////////
	// Look Inside Toggle
	
	$(".look_inside_toggle").click(function () {
		$('#look_inside').toggle(0);
		return false;
	});
	
	$("#look_inside").bind( "clickoutside", function(event){
		$(this).fadeOut(200);
	});
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	(function($){
		$.fn.clearDefault = function(){
			return this.each(function(){
				var default_value = $(this).val();
				$(this).focus(function(){
					if ($(this).val() == default_value) $(this).val("");
				});
				$(this).blur(function(){
					if ($(this).val() == "") $(this).val(default_value);
				});
			});
		};
	})(jQuery);
	
	$('table input:not(.clear)').clearDefault();
	
});

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

