/* Copyright (c) 2008 Kean Loong Tan http://www.gimiti.com/kltan
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * jFlow
 * Version: 1.1 (May 22, 2008)
 * Requires: jQuery 1.2+
 */
(function(A){A.fn.jFlow=function(D){var E=A.extend({},A.fn.jFlow.defaults,D);var F=0;var B=A(".jFlowControl").length;A(this).find(".jFlowControl").each(function(G){A(this).click(function(){A(".jFlowControl").removeClass("jFlowSelected");A(this).addClass("jFlowSelected");var H=Math.abs(F-G);A(E.slides).animate({marginLeft:"-"+(G*A(E.slides).find(":first-child").width()+"px")},E.duration*(H));F=G})});A(E.slides).before('<div id="jFlowSlide"></div>').appendTo("#jFlowSlide");A(E.slides).find("div").each(function(){A(this).before('<div class="jFlowSlideContainer"></div>').appendTo(A(this).prev())});A(".jFlowControl").eq(F).addClass("jFlowSelected");var C=function(G){A("#jFlowSlide").css({position:"relative",width:E.width,height:E.height,overflow:"hidden"});A(E.slides).css({position:"relative",width:A("#jFlowSlide").width()*A(".jFlowControl").length+"px",height:A("#jFlowSlide").height()+"px",overflow:"hidden"});A(E.slides).children().css({position:"relative",width:A("#jFlowSlide").width()+"px",height:A("#jFlowSlide").height()+"px","float":"left"});A(E.slides).css({marginLeft:"-"+(F*A(E.slides).find(":first-child").width()+"px")})};C();A(window).resize(function(){C()});A(".jFlowPrev").click(function(){if(F>0){F--}else{F=B-1}A(".jFlowControl").removeClass("jFlowSelected");A(E.slides).animate({marginLeft:"-"+(F*A(E.slides).find(":first-child").width()+"px")},E.duration);A(".jFlowControl").eq(F).addClass("jFlowSelected")});A(".jFlowNext").click(function(){if(F<B-1){F++}else{F=0}A(".jFlowControl").removeClass("jFlowSelected");A(E.slides).animate({marginLeft:"-"+(F*A(E.slides).find(":first-child").width()+"px")},E.duration);A(".jFlowControl").eq(F).addClass("jFlowSelected")})};A.fn.jFlow.defaults={easing:"swing",duration:400,width:"100%"}})(jQuery);

$(document).ready(function(){  
 
     //Caption Sliding (Partially Hidden to Visible)  
     $('.boxgrid.caption').hover(function(){  
         $(".cover", this).stop().animate({top:'54px'},{queue:false,duration:160});  
     }, function() {  
         $(".cover", this).stop().animate({top:'129px'},{queue:false,duration:160});  
     });  
 });

$(function () {
  
  $('.bottom-content')
    
    // within the context of the bottom-content element, find the a.button elements
    .find('a.button')
    
    // create our new span.hover and loop through anchor:
    .append('<span class="hover" />').each(function () {
      
      // cache a copy of the span, at the same time changing the opacity
      // to zero in preparation of the page being loaded
      var $span = $('> span.hover', this).css('opacity', 0);
      
      // when the user hovers in and out of the anchor
      $(this).hover(function () {
        // on hover
        
        // stop any animations currently running, and fade to opacity: 1
        $span.stop().fadeTo(500, 1);
      }, function () {
        // off hover
        
        // again, stop any animations currently running, and fade out
        $span.stop().fadeTo(500, 0);
      });
    });
});

$(function () {
  
  $('#button-left, #button-right')
    
    // within the context of the bottom-content element, find the a.button elements
    .find('span.fade')
    
    // create our new span.hover and loop through anchor:
    .append('<span class="hover" />').each(function () {
      
      // cache a copy of the span, at the same time changing the opacity
      // to zero in preparation of the page being loaded
      var $span = $('> span.hover', this).css('opacity', 0);
      
      // when the user hovers in and out of the anchor
      $(this).hover(function () {
        // on hover
        
        // stop any animations currently running, and fade to opacity: 1
        $span.stop().fadeTo(500, 1);
      }, function () {
        // off hover
        
        // again, stop any animations currently running, and fade out
        $span.stop().fadeTo(500, 0);
      });
    });
});

$(function () {
  
  $('#nav')
    
    // within the context of the bottom-content element, find the a.button elements
    .find('span.span-text')
    
    // create our new span.hover and loop through anchor:
    .append('<span class="hover" />').each(function () {
      
      // cache a copy of the span, at the same time changing the opacity
      // to zero in preparation of the page being loaded
      var $span = $('> span.hover', this).css('opacity', 0);
      
      // when the user hovers in and out of the anchor
      $(this).hover(function () {
        // on hover
        
        // stop any animations currently running, and fade to opacity: 1
        $span.stop().fadeTo(500, 1);
      }, function () {
        // off hover
        
        // again, stop any animations currently running, and fade out
        $span.stop().fadeTo(500, 0);
      });
    });

	$("span.span-text").click(function(){
			
			$("span.active").addClass("span-text");
			$("span.active").removeClass("active");
			
			$(this).addClass("active");
			$(this).removeClass("span-text");
	});
	
	$("a.second").click(function(){
			
			$("span.active").addClass("span-text");
			$("span.active").removeClass("active");
			
			var switcher = $(this).attr("title");
			
			$("."+switcher).addClass("active");
			$("."+switcher).removeClass("span-text");
	});

});

$(document).ready(function(){



	$("span.active").removeClass("span-text");
	try {
	$("#myController").jFlow({
		slides: "#slides",
		width: "602px",
		height: "359px",
		duration: 400
	});
	
	} catch(err) {}
});

$(document).ready(function()
{
	//fade("#sliding-navigation", 25, 15, 150, .8);
	// When a link is clicked
		$("a.tab").click(function () {
			
			// slide all content up
			$("div.content").fadeOut(1000);
			
			// slide this content up
			var content_show = $(this).attr("title");
			$("#"+content_show).fadeIn(1000);
		  
		});
	
});

$(document).ready(function(){
	$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailToVal = $("#emailTo").val();
		if(emailToVal == '') {
			$("#emailTo").after('<span class="error">You forgot to enter the email address to send to.</span>');
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {	
			$("#emailTo").after('<span class="error">Enter a valid email address to send to.</span>');
			hasError = true;
		}
		
		var emailFromVal = $("#emailFrom").val();
		if(emailFromVal == '') {
			$("#emailFrom").after('<span class="error">You forgot to enter the email address to send from.</span>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$("#emailFrom").after('<span class="error">Enter a valid email address to send from.</span>');
			hasError = true;
		}
		
		var subjectVal = $("#subject").val();
		if(subjectVal == '') {
			$("#subject").after('<span class="error">You forgot to enter the subject.</span>');
			hasError = true;
		}
		
		var messageVal = $("#message").val();
		if(messageVal == '') {
			$("#message").after('<span class="error">You forgot to enter the message.</span>');
			hasError = true;
		}
		
		
		if(hasError == false) {
			$(this).hide();
			$("#sendEmail li.buttons").append('<p>Loading</p>');
			
			$.post("sendemail.php",
   				{ emailTo: emailToVal, emailFrom: emailFromVal, subject: subjectVal, message: messageVal },
   					function(data){
						$("#sendEmail").fadeOut(1500, function() {				   
							
							$("#sendEmail").before('<h3>Thank you</h3><p>I have received you email and will be in contact as soon as possible.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});						   
});
