DEBUG = true;

$(function(){

function showDrop() {
	/*switch($(this).attr('id')) {
		case 'nav_brandable':
			$("#drop_brandable").slideDown('fast');
		break;
		case 'nav_blitz':
			$("#drop_blitz").slideDown('fast');
		break;
	}*/
		//$("div.drop").hide();
		//$(this).find('div').debug();
		//alert($(this).find('div'));
		//$(this).find('.drop').debug();
		$(this).find('div.drop').slideDown('fast');
		return false;
}

function hideDrop() {
	/*switch($(this).attr('id')) {
		case 'nav_brandable':
			$("#drop_brandable").slideUp('fast');
		break;
		case 'nav_blitz':
			$("#drop_blitz").slideUp('fast');
		break;
	}*/
		$(this).find('div.drop').hide();
		return false;
}



var config = {    
     sensitivity: 2,
     interval: 200,
     over: showDrop,
     timeout: 300,
     out: hideDrop
};

$("#nav_brandable").hoverIntent( config );
$("#nav_blitz").hoverIntent( config );
$("#nav_dogoods").hoverIntent( config );
$("#nav_bcommerce").hoverIntent( config );
$("#nav_sitewrite").hoverIntent( config );
$("#nav_design").hoverIntent( config );
$("#nav_stores").hoverIntent( config );
$("#nav_company").hoverIntent( config );



$("#nav_brandable").click(
      function () {
		if($("#drop_brandable").is(':visible')) {
			//$("#drop_brandable").slideUp('fast');
		} else {
			$("div.drop").hide();
			$("#drop_brandable").slideDown('fast');
		}
      }
);

$("#nav_blitz").click(
      function () {
		if($("#drop_blitz").is(':visible')) {
			//$("#drop_blitz").slideUp('fast');
		} else {
			$("div.drop").hide();
			$("#drop_blitz").slideDown('fast');
		}
      }
);

$("#nav_dogoods").click(
      function () {
		if($("#drop_dogoods").is(':visible')) {
			//$("#drop_dogoods").slideUp('fast');
		} else {
			$("div.drop").hide();
			$("#drop_dogoods").slideDown('fast');
		}
      }
);

$("#nav_bcommerce").click(
      function () {
		if($("#drop_bcommerce").is(':visible')) {
			//$("#drop_bcommerce").slideUp('fast');
		} else {
			$("div.drop").hide();
			$("#drop_bcommerce").slideDown('fast');
		}
      }
);

$("#nav_sitewrite").click(
      function () {
		if($("#drop_sitewrite").is(':visible')) {
			//$("#drop_sitewrite").slideUp('fast');
		} else {
			$("div.drop").hide();
			$("#drop_sitewrite").slideDown('fast');
		}
      }
);

$("#nav_design").click(
      function () {
		if($("#drop_design").is(':visible')) {
			//$("#drop_design").slideUp('fast');
		} else {
			$("div.drop").hide();
			$("#drop_design").slideDown('fast');
		}
      }
);

$("#nav_stores").click(
      function () {
		if($("#drop_stores").is(':visible')) {
			//$("#drop_stores").slideUp('fast');
		} else {
			$("div.drop").hide();
			$("#drop_stores").slideDown('fast');
		}
      }
);

$("#nav_company").click(
      function () {
		if($("#drop_company").is(':visible')) {
			//$("#drop_company").slideUp('fast');
		} else {
			$("div.drop").hide();
			$("#drop_company").slideDown('fast');
		}
      }
);


/* *************** */

$("#nav_brandable").hover(
	function() {
		$("#nav_brandable_hover").fadeIn('fast');
		$("#nav_brandable .off").fadeOut('fast');
	},
	function() {
		$("#nav_brandable_hover").fadeOut('fast');
		$("#nav_brandable .off").fadeIn('fast');
	}
);

$("#nav_blitz").hover(
	function() {
		$("#nav_blitz_hover").fadeIn('fast');
		$("#nav_blitz .off").fadeOut('fast');
	},
	function() {
		$("#nav_blitz_hover").fadeOut('fast');
		$("#nav_blitz .off").fadeIn('fast');
	}
);

$("#nav_dogoods").hover(
	function() {
		$("#nav_dogoods_hover").fadeIn('fast');
		$("#nav_dogoods .off").fadeOut('fast');
	},
	function() {
		$("#nav_dogoods_hover").fadeOut('fast');
		$("#nav_dogoods .off").fadeIn('fast');
	}
);
$("#nav_bcommerce").hover(
	function() {
		$("#nav_bcommerce_hover").fadeIn('fast');
		$("#nav_bcommerce .off").fadeOut('fast');
	},
	function() {
		$("#nav_bcommerce_hover").fadeOut('fast');
		$("#nav_bcommerce .off").fadeIn('fast');
	}
);

$("#nav_sitewrite").hover(
	function() {
		$("#nav_sitewrite_hover").fadeIn('fast');
		$("#nav_sitewrite .off").fadeOut('fast');
	},
	function() {
		$("#nav_sitewrite_hover").fadeOut('fast');
		$("#nav_sitewrite .off").fadeIn('fast');
	}
);

$("#nav_design").hover(
	function() {
		$("#nav_design_hover").fadeIn('fast');
		$("#nav_design .off").fadeOut('fast');
	},
	function() {
		$("#nav_design_hover").fadeOut('fast');
		$("#nav_design .off").fadeIn('fast');
	}
);

$("#nav_stores").hover(
	function() {
		$("#nav_stores_hover").fadeIn('fast');
		$("#nav_stores .off").fadeOut('fast');
	},
	function() {
		$("#nav_stores_hover").fadeOut('fast');
		$("#nav_stores .off").fadeIn('fast');
	}
);

$("#nav_company").hover(
	function() {
		$("#nav_company_hover").fadeIn('fast');
		$("#nav_company .off").fadeOut('fast');
	},
	function() {
		$("#nav_company_hover").fadeOut('fast');
		$("#nav_company .off").fadeIn('fast');
	}
);



var active_image = 0;
$("a.bblink").click(function(){document.location.href = billboard_urls[active_image]; return false;});

$("img.i0").everyTime(5000, function () {
	var prev_image = active_image;
	active_image++;
	if(active_image == total_billboard_images)
		active_image = 0;
$("img.i"+active_image).fadeIn('fast');
$("a.bblink").unbind('click');
$("a.bblink").click(function(){

document.location.href = billboard_urls[active_image];
return false;
});
$("img.i"+prev_image).fadeOut('fast');

});



var right_active_image = 0;


$("img.ri0").everyTime(8000, function () {

	var right_prev_image = right_active_image;
	right_active_image++;
	if(right_active_image == total_right_images)
		right_active_image = 0;
	$("img.ri"+right_active_image).fadeIn(1000);
	$("img.ri"+right_prev_image).fadeOut(2000);
	}

);

});
// stuff moved from code

$(function(){

$("#l_l1").click(function(){
	if($("#l_d1").is(':visible'))
		$("#l_d1").fadeOut(100);
	else
		$("#l_d1").fadeIn(100);
	return false;
});

/*$("a.popform").click(function() {
	$("#testformdiv").slideToggle(500);
	return false;
});*/


$("#leftnavul > li > a").click(
      function (event) {
		//alert($(this).attr('href'));
			$(this).parent().find('ul').not('.leftfooter').not('.noslide').slideToggle('fast');
			return false;
      }
);

$("#leftnavul ul").not('.leftfooter').not('.active').hide();

$('h1.red').sifr( { strSWF: WEB_ROOT+"webLetterer.swf", strColor: '#CD2036', strBgColor: '#FFFFFF', strLinkColor: '#000000', strHoverColor: '#CCCCCC', intPadding: [0, 0, 0, 0], strWmode: 'opaque'} );


$('h1:not(.no):not(.red)').sifr( { strSWF: WEB_ROOT+"webLetterer.swf", strColor: '#2982C6', strBgColor: '#FFFFFF', strLinkColor: '#000000', strHoverColor: '#CCCCCC', intPadding: [0, 0, 0, 0], strWmode: 'opaque'} );

$('.relatedcats').sifr( { strSWF: WEB_ROOT+"webLetterer.swf", strColor: '#CD2036', strBgColor: '#FFFFFF', strLinkColor: '#000000', strHoverColor: '#CCCCCC', intPadding: [0, 0, 0, 0], strWmode: 'opaque'} );


$(document).click(
	function() {
		$("div.drop").hide();
	}
);


var submitcontact = function() {

$.ajax({
	type : "POST",
	data : $("#contactform").formSerialize(),
	url : WEB_ROOT+'form.php',
	dataType : 'json',
	success: function(json) {

		switch(json.result) {
			case 1: // success!
				$("#contactformid").html('<span style="red">Your request has been submitted. You will receive a response within one business day. If this is for a rush item, you may also call us at 760-231-9977.</span>');
			break;
			case 2: // error!
				$("#submitform").val('Submit');
				$("#submitform").attr("disabled","");
				
			break;
		}
		//$("#contactform").append(json.result);
		//$("#contactformid").html(json);
	}
});
$("#submitform").val('Please wait...');
$("#submitform").attr("disabled","disabled");
return false;
};


$('#dialog').jqm();


$("#contactform").validate({
	rules: {
		"f[name]": {
			required:true,
			minLength:2
		},
		"f[company]": {
			required:true,
			minLength:2
		},
		"f[phone]": {
			required:true,
			minLength: 10
		},
		"f[email]": {
			required: true,
			email: true
		},
		"f[qty]": "required",
		captcha: {
			required: true,
			remote: WEB_ROOT+"captcha/process.php"
		}

	},
	messages: {
		"f[name]": "&lt;&lt;",
		"f[company]": "&lt;&lt;",
		"f[phone]": "&lt;&lt;",
		"f[email]": "&lt;&lt;",
		"f[qty]": "&lt;&lt;",
		captcha: "Correct captcha is required. Click the captcha to generate a new one"	
	},
	submitHandler: function() { submitcontact(); }

});


/*Recaptcha.create("6LfLrgEAAAAAAF-3wndarB_yG-xhYUebQwctI1T1",
"recaptcha_div", {
   theme: "custom",
   callback: Recaptcha.focus_response_field
});*/


	$("#refreshimg").click(function(){

		$.post(WEB_ROOT+'captcha/newsession.php');
		$("#refreshimg").load(WEB_ROOT+'captcha/image_req.php');
		return false;
	});

/*
	
	$("#captchaform").validate({
		rules: {
		},
		messages: {
		},
		submitHandler: function() {
			alert("Correct captcha!");
		},
		success: function(label) {
			label.addClass("valid").text("Valid captcha!")
		},
		onkeyup: false
	});
*/


});

