/***********************************************
* 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";});
	$("#logo").css('cursor', 'pointer').click( function() { window.location = './';});
	
	/*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();
	});
	
  // $("body#contact .cmxform").submit(function() {
  //     var s1 = 'enquiries';
  //     var s2 = '@';
  //     var s3 = 'arcarocouture.com.au';
  //     $(this).append('<input type="hidden" name="Email_To" value="' + s1 + s2 + s3 + '" />');
  //   });

	$("body#contact .cmxform").submit(function() {
    var s1 = 'enquiries';
    var s2 = '@';
    var s3 = 'arcarocouture.com.au';
    $(this).append('<input type="hidden" name="Email_To" value="' + s1 + s2 + s3 + '" />');
  });

	
	/*set hover class for anything*/
	$('form.cmxform input.send').css('cursor', 'pointer').hover(function() {$(this).addClass('sendhover');}, function() {$(this).removeClass('sendhover');});
	$('ul#thumbnails li').css('cursor', 'pointer');
	$('#thumbnav').css('overflow-y', 'hidden');
	$('#tooltip').css('opacity', '0.85');
	
	/*fade in open with set time delay before automatically fade out*/
	$('#map img').hide();
	$('a.openmap').click(function() {$('#map img').fadeIn('slow').animate({opacity: 1.0}, 20000).fadeOut('slow', function() {$(this).hide();});});
	
	/*sub gallery*/
	$('ul#thumbnails li').click(function() {$('#gallery-display2').hide();});
	$('ul.sub-gallery li a').click(function() {$('#gallery-display2').show();});

	/*gallaria*/
	$('ul#thumbnails').galleria({
			history   : true,
			clickNext : true,
			insert    : '#gallery-display', 
			onImage   : function(image,caption,thumb) {
				// fade in the image & caption
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.35);
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				// add a title for the clickable image
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) {
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.5';
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.35); }
				)
			}
		});			
	
});


/***********************************************
* Safe email links
***********************************************/

function hideEmail() {
	var s1 = "enquiries";
	var s2 = "@";
	var s3 = "arcarocouture.com.au";
	var s4 = "?Subject=Enquiry%20from%20" + s3;
	var s5 = s1 + s2 + s3;
	document.write("<a href=" + "mail" + "to:" + s1 + s2 + s3 + s4 + ">" + s5 + "</a>");
}


/***********************************************
* Form fields Validation Script
***********************************************/

function ValidateForm(f){

	with(f){
		if (isEmpty(_1_Name.value)) {alert("Please enter your Name");_1_Name.focus();return false;}
		if (isEmpty(_2_Email_From.value)) {alert("Please enter your Email Address");_2_Email_From.focus();return false;}
		if ( !isEmail(_2_Email_From.value) ) {alert("Please enter a valid Email Address."); _2_Email_From.focus();return false;}
		if (!isEmpty(_3_Phone_or_Fax.value)) {if (!IsNumber(_3_Phone_or_Fax.value, true)) {alert("Please enter only numbers for your Phone and Fax");_3_Phone_or_Fax.focus();return false;}}
		if (isEmpty(_4_Gown_Name.value)) {alert("Please enter a Gown Name");_4_Gown_Name.focus();return false;}
		if (isEmpty(_5_Enquiries.value)) {alert("Please enter your Enquiry");_4_Enquiries.focus();return false;}
	}
	return true;
 }

/***********************************************
* ShowandHide Script - if not using jquery
***********************************************/

function viewinfo(id) {
	box = document.getElementById(id);
	box.className = "visible";

	//Now hide all other divs that are visible
	var oDivs = document.getElementsByTagName("div")

	for (var i=0; i<oDivs.length; i++)
		if (oDivs[i].className=="visible" && oDivs[i].id != id)
			oDivs[i].className = "hidden";
}

