/***********************************************
* jQuery functions execute
***********************************************/

$(document).ready(function() {                
              
	/*cmx form */
	if(jQuery.browser.mozilla) {
		$('form.cmxform').hide().find('label:not(.nocmx)').each(function(){
                          	var $labelContent = $(this).html();
                                       var $labelWidth = $(this).css('width');
                                       $(this).empty();
                                       $(this).append('<span style="display: block; width: '+$labelWidth+';">');
                                       $(this).prepend('</span>');
                                       $(this).css('display', '-moz-inline-box');
                                       $(this).find('span').html($labelContent);
                                       $('form.cmxform').show();
                                });
                };             


	/*external link*/
	$('a[@rel$="external"]').click(function(){this.target = "_blank";});
	/*thickbox opacity*/	
	$('.thickbox').click(function() {$('.TB_overlayBG').css('opacity', '0.75');});
	
	/*email protect*/
	$("span.safemail").each(function(){
		exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
		match = exp.exec($(this).text());
		addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
		link = match[2] ? match[2] : addr;
		subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
		$(this).after('<a href="mailto:'+addr+subject+'">'+ link + '</a>');
		$(this).remove();
	});
	
	/*rounded corners*/
	$('.contents').corner("round 10px top bottom");
	$('.crumbs').corner("round 10px top bottom");
	//definition can be top, bottom, tl, tr, bl, br//
			
	/*disable input box and textrea at confirmation page*/
	$('.confirmation textarea').attr("disabled", true);
	$('.confirmation input').attr("disabled", true);

	/* enable submit buttons */
	$('.confirmation input.send').attr("disabled", false);	

	/*run on form submit */
	$('form#OrderForm').submit(function(){
		/*enable input box and textrea at confirmation page*/
		$('.confirmation textarea').attr("disabled", false);
		$('.confirmation input').attr("disabled", false);

		/*enable input and select box on checkout page */
		$('.checkout select').attr("disabled", false);
		$('.checkout input').attr("disabled", false);
	});

	// links on the confirmation page that go back to the checkout page
	$('a.checkoutbacklink, input#Back').click(function () {
		//change where the form is posting to
		$("form#OrderForm").attr("action", "checkout.asp");

		//remove the form target (the popup)
		$("form#OrderForm").attr("target", "");

		/*enable input box and textrea at confirmation page*/
		$(".confirmation textarea").attr("disabled", false);
		$(".confirmation input").attr("disabled", false);

		//submit our form
		$("form#OrderForm").submit();

		return false;
	});

	//hide our delivery postcode option	
	$("#DeliveryPostcodeOption").hide();

	//run when the delivery country changes
	$("#DeliveryDestination").change(function(event) {
		//ensure our changed event is the select box
		if ( $(event.target).is("option") || $(event.target).is("select") ) {
			//check to see if the country is australia
			if ( $(this).val() == "Australia" ) {
				//show the delivery postcode option
				$("#DeliveryPostcodeOption").toggle(300);
			}
			else {
				//hide the delivery postcode option
				$("#DeliveryPostcodeOption").hide();
			}
		}
	});

	/*set hover class for anything*/
	$('input.send').css('cursor', 'pointer').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
	$('form.cmxform input.send').css('cursor', 'pointer').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
	$('ul#catalogue-nav li').css('cursor', 'pointer').hover(function() {$(this).addClass('over');}, function() {$(this).removeClass('over');});
	$('.button input').css('cursor', 'pointer').hover(function() {$(this).addClass('subhover');}, function() {$(this).removeClass('subhover');});
	
	/*simple hide and show*/
	$('div.quote').hide();
	$('h3 a.open-quote').click(function() {$('div.quote').toggle(400);return false;});	
	
	/*advanced hide and show*/
	$('ul.product_range li> ul').hide();
	$('ul.product_range li> a').click(function() {
	$(this).next('ul').slideToggle('fast')
	.parent().siblings('li').find('ul:visible').slideUp('fast');});
	
	/*show hide id*/
	$('div.item').hide();
	$("#privacy-fence").show();
	$('div.products ul li a').click(function() {
		var category = "#" + $(this).attr('rel');
		$('div.item').fadeOut("fast");
		$(category).fadeIn("slow");
		return false;
	});
	
});


/***********************************************
* Safe email links - hide Email To field
***********************************************/

function hide_EmailForm() {
	var s1 = 'info';
	var s2 = '@';
	var s3 = 'ritzipoochi.com.au';
	document.write('<input type="hidden" name="Em' + 'ail_To" value="' + s1 + s2 + s3 + '" />');
}
