//
//     Platina [ Premium Portfolio, Photography & Business Template ]
//     Developed By ~ QuadCodes
//     Date ~ 01/02/2011
//     Version ~ 1.0
//     Website ~ http://quadcodes.com/
//     --------------------------------
//	
//     template.js ~ This js file contains custom codes to enhance functionality of this theme:
//	
//			    1. JQuery Scroll Top
//			    2. JQuery Preload Image
//			    3. JQuery Slider
//			    4. JQuery Cycle Plugin
//			    5. JQuery Tab
//			    6. JQuery ThumbPort
//			    7. JQuery Contact Form
//			    8. JQuery Equal Heights
//			    9. Cufon
//
//
//



//////////////////// 1. JQuery Scroll Top ///////////////////////

$(document).ready(function() {
    $('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });

});


//////////////////// 2. JQuery Preload Image ///////////////////////

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

// Add path to the images that you want to Preload //

$(document).ready(function(){ 
jQuery.preLoadImages("../img/zoom.png");
});


//////////////////// 3. JQuery Slider ///////////////////////

 $(document).ready(function(){ 
    $('#sildercontent').suSlider(); 
 });


//////////////////// 4. JQuery Cycle Plugin ///////////////////////

$(function() {
    $('.featured_1').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev1',
        next:    '#next1'        
    });
    $('.featured_2').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev2',
        next:    '#next2'        
            });
    $('.featured_3').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev3',
        next:    '#next3'        
    });
    $('.featured_4').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev4',
        next:    '#next4'        
    });
    $('.featured_5').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev5',
        next:    '#next5'        
            });
    $('.featured_6').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev6',
        next:    '#next6'        
    }); 
    $('.full_img').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev',
        next:    '#next'        
    });        
});


//////////////////// 5. JQuery Tab ///////////////////////

$(document).ready(function() { 
	$('.tabs a').click(function(){
		switch_tabs($(this));
	}); 
	switch_tabs($('.defaulttab')); 
    }); 
    function switch_tabs(obj) {
	$('.tab-content').hide();
	$('.tabs a').removeClass("selected");
	var id = obj.attr("rel"); 
	$('#'+id).fadeIn(500);
	obj.addClass("selected");
    }


//////////////////// 6. JQuery ThumbPort ///////////////////////

$(document).ready(function() {
        $('.thumbport').mouseenter(function(e) {
            $(this).children('a').children('img').animate({ height: '110', left: '0', top: '0', width: '190'}, 100);
            $(this).children('a').children('span').fadeIn(200);
        }).mouseleave(function(e) {
            $(this).children('a').children('img').animate({ height: '110', left: '0', top: '0', width: '190'}, 100);
            $(this).children('a').children('span').fadeOut(200);
        });
        $('.two_c_img').mouseenter(function(e) {
            $(this).children('a').children('img').animate({ height: '190', left: '0', top: '0', width: '355'}, 100);
            $(this).children('a').children('span').fadeIn(200);
        }).mouseleave(function(e) {
            $(this).children('a').children('img').animate({ height: '190', left: '0', top: '0', width: '355'}, 100);
            $(this).children('a').children('span').fadeOut(200);
        });
        $('.three_c_img').mouseenter(function(e) {
            $(this).children('a').children('img').animate({ height: '125', left: '0', top: '0', width: '210'}, 100);
            $(this).children('a').children('span').fadeIn(200);
        }).mouseleave(function(e) {
            $(this).children('a').children('img').animate({ height: '125', left: '0', top: '0', width: '210'}, 100);
            $(this).children('a').children('span').fadeOut(200);
        });
        $('.shoot').mouseenter(function(e) {
            $(this).children('a').children('img').animate({ height: '480', left: '0', top: '0', width: '320'}, 100);
            $(this).children('a').children('span').fadeIn(200);
        }).mouseleave(function(e) {
            $(this).children('a').children('img').animate({ height: '480', left: '0', top: '0', width: '320'}, 100);
            $(this).children('a').children('span').fadeOut(200);
        });
    });



//////////////////// 7. JQuery Contact Form ///////////////////////

$(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>')
			.addClass('error_input')
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {	
			$("#emailTo").after('<span class="error">*Enter a valid email address to send to.</span>')
			.addClass('error_input')
			hasError = true;
		}
		
		var emailFromVal = $("#emailFrom").val();
		if(emailFromVal == '') {
			$("#emailFrom").after('<span class="error">*You forgot to enter the email address to send form.</span>')
			.addClass('error_input')
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$("#emailFrom").after('<span class="error">*Enter a valid email address to send form.</span>')
			.addClass('error_input')
			hasError = true;
		}
		
		var subjectVal = $("#subject").val();
		if(subjectVal == '') {
			$("#subject").after('<span class="error">*You forgot to enter the subject.</span>')
			.addClass('error_input')
			hasError = true;
		}
		
		var messageVal = $("#message").val() + ' ' + $("#telephone").val();
		if(messageVal == '') {
			$("#message").after('<span class="error">*You forgot to enter the message.</span>')
			.addClass('error_input')
			hasError = true;
		}
		
		var telephoneVal = $("#telephone").val();
          if(subjectVal == '') {
               $("#message").after('<span class="error">*You forgot to enter the message.</span>')
               .addClass('error_input')
               hasError = true;
          }  
		
		// remove "error" class from text fields
		$("form input, form textarea").focus(function() {
 			$(this).removeClass('error_input');
		});
		
		// remove error messages when user starts typing		
		$("form input, form textarea").keypress(function() {
 			$(this).parent().find('span').fadeOut();	
		});
		
		if(hasError == false) {
			$(this).hide();
			$("#sendEmail li.buttons").append('<img src="http://workspace.quadcodes.com/corp2/img/loading.gif" alt="Loading" id="loading" />');
			
			$.post("http://workspace.quadcodes.com/corp2/contact_form/sendEmail.php",
   				{ emailTo: emailToVal, emailFrom: emailFromVal, subject: subjectVal, message: messageVal, telephone: telephoneVal },  
   					function(data){
						$("#sendEmail").slideUp("normal", function() {				   
							
							$("#sendEmail").before('<h2>Thank you !</h2><br><p>Our representative shall contact you within 2 business days.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});						   
});


//////////////////// 8. JQuery Equal Heights ///////////////////////

function equalHeight(group) {
    tallest = 0;
    group.each(function() {
    thisHeight = $(this).height();
    if(thisHeight > tallest) {
         tallest = thisHeight;
    }
    });
    group.height(tallest);
    }
    $(document).ready(function() {
    equalHeight($(".eh"));
});

//////////////////// 9 .CUFON  /////////////////////// 

$(document).ready(function(){
		Cufon.replace("h1", {hover: true});
                Cufon.replace("h2", {hover: true});
                Cufon.replace("h3", {hover: true});
                Cufon.replace(".parent", { fontFamily: 'Code Bold' });
                Cufon.replace(".bold", { fontFamily: 'Code Bold' });
                Cufon.replace("h4", {hover: true}); 
});



