/***********************************************
* 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.85');});
	$('#flash-logo').css('cursor', 'pointer').click( function() { window.location = './';});
	$('.cart img').css('cursor', 'pointer');
	$('.alpha-top').css('cursor', 'pointer');
	
	/*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();
	});
	
	/*image cycle*/
	$('#cycle').cycle({ 
		fx:    'fade', 
		speed:  4000
	});
	
	/*rounded corners*/
	$('.right-panel').corner();
	$('ul.links-listing li').corner();
	$('.tl').corner("tl");
	$('.tr').corner("tr");

	/*on focus for input boxes*/
	$.fn.search = function() {
		return this.focus(function() {if( this.value == this.defaultValue ) {this.value = "";}})
		.blur(function() {if( !this.value.length ) {this.value = this.defaultValue;}});};
	$("input#Keyword_Search").search();

	/*make sure search has enough characters*/
	$("form#QuickSearch").submit(function(){
		if($("input#Keyword_Search").val().length <= 2)
		{
			alert("Please supply at least 3 characters");
			$("input#Keyword_Search").focus();
			return false;
		}
	});

	/*disable input box at confirmation*/
	$('.confirmation input').attr("disabled", true);
	$('.confirmation input.send').attr("disabled", false);	
		
	/*set hover class for anything*/
	$('a.go').hover(function() {$(this).addClass('gohover');}, function() {$(this).removeClass('gohover');});
	$('#category-listing li').css('cursor', 'pointer').hover(function() {$(this).addClass('cathover');}, function() {$(this).removeClass('cathover');});
	$('input.send').css('cursor', 'pointer').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
	$('input.qsearch').css('cursor', 'pointer').hover(function() {$(this).addClass('searchhover');}, function() {$(this).removeClass('searchhover');});
	$('input.advanced_search').css('cursor', 'pointer').hover(function() {$(this).addClass('searchhover');}, function() {$(this).removeClass('searchhover');});
	$('form.cmxform input.send').css('cursor', 'pointer').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
	$('.thumb').css('cursor', 'pointer').hover(function() {$(this).addClass('thumbhover');}, function() {$(this).removeClass('thumbhover');});
	$('ul.detail-thumbs li').css('cursor', 'pointer').hover(function() {$(this).addClass('frameover');}, function() {$(this).removeClass('frameover');});
	
	/*ie6 dropdown fix*/
	$('ul#nav li').hover(function() {$(this).addClass('over');}, function() {$(this).removeClass('over');});
	$('ul#nav li li').hover(function() {$(this).addClass('over2');}, function() {$(this).removeClass('over2');});
	$('ul#nav ul').hover(function() {$('.over a').addClass('onsection');}, function() {$('.over a').removeClass('onsection');});
	$('ul#nav li li').hover(function() {$('.over a').addClass('onsection');}, function() {$('.over a').removeClass('onsection');});
	$('ul#nav li li li').hover(function() {$('.over2').addClass('onsection2');}, function() {$('.over2').removeClass('onsection2');});
	
	/*simple hide and show*/
	$('div.quote').hide();
	$('h3 a.open-quote').click(function() {$('div.quote').toggle(400);return false;});
		
	/*radio button hide one show one*/
	$("#select-package").hide();
	$("input[@name='Step2']").click(function(){
	$("input[@name='Step2']:checked").val() == 1 ? $('#select-package').toggle(300) : $('#select-package').slideUp('fast');
	});

	/*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');});
	
	/*radio button for checkout option*/
	$("#CC-info").hide();
	$("#PP-info").hide();
	$("input[@name='Payment_Options']").click(function(){
	$("input[@name='Payment_Options']:checked").val() == 0 ? $('#CC-info').toggle(300) : $('#CC-info').slideUp('fast');
	$("input[@name='Payment_Options']:checked").val() == 1 ? $('#PP-info').toggle(300) : $('#PP-info').slideUp('fast');
	});

	//changes youtube videos on the home page
	$(".video-change").click(function() {
		var so = new SWFObject($(this).attr("href"), "movie", "270", "180", "8");
		so.addParam("allowFullScreen", "true");
		so.addParam("allowscriptaccess", "always");
		so.addParam("quality", "best");
		so.addParam("menu", "false");
		so.addParam("wmode", "transparent");
		so.write("video"); 
		return false;
	});
});


/***********************************************
* Safe email links - hide Email To field
***********************************************/

function hide_EmailForm() {
	var s1 = 'ioscar';
	var s2 = '@';
	var s3 = 'webfirm.com.au';
	document.write('<input type="hidden" name="Em' + 'ail_To" value="' + s1 + s2 + s3 + '" />');
}

