$(document).ready(function() {                

	/*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();
	});    



	// Open links in new window when rel="external" is applyed to a tag
	$('a[rel="external"]').click(function(){
		this.target = "_blank";
	});
	
	
  //hide email and add the hidden email_To on submit
  $("#enquiryform").submit(function() {
    var s1 = 'celine.chung';
    var s2 = '@';
    var s3 = 'webfirm.com';
    $(this).append('<input type="hidden" name="Email_To" value="' + s1 + s2 + s3 + '" />');
  });


 $('#slideshow').cycle({fx: 'fade', timeout: 5000, speed: 2000});

 $('div.hidden:not(:first)').hide();
 
 $('ul.products li > a').click(function(event) {
    //prevent the default action for the click event
    event.preventDefault();

    var cat = $(this).attr('href');
    
    //$('ul.products li > a').style('background-color: white');
    $('ul.products li > a').removeClass('selected_section');
    $(this).addClass('selected_section');
    
    $('div.hidden').hide();
    $(cat).fadeIn("slow");

    $('html, body').animate({scrollTop:445}, 500);
  });

  $( "a > img").hover(function () {
    $(this).fadeTo("slow", 0.50);
    $(this).fadeTo("fast", 0.90);
  });

});
