//
//     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
//                          10. DROP-DOWN MENU          
//
//
//

//////////////////// 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", "../img/arrow.png", "../img/arrow_hover.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}); 
});


///////////////////// 10. DROPDOWN MENU //////////////

$(document).ready(function(){

	$("ul.subnav").parent().append("<div></div>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav

	$("ul.topnav li div").mouseenter(function() { //When trigger is clicked...

                if ($.browser.msie  && parseInt($.browser.version) == 8) {
                $(this).css("padding", "10 0");
                } else {}
		
		//IF !IE 7
                if ($.browser.msie  && parseInt($.browser.version) == 7) {
                } else {
                //Add Active class
		$(this).parent().addClass('active');
		Cufon.replace('.topnav li span a', {fontFamily: 'Code bold'});
                }
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast'); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
			
			//Remove Active class with delay
			setTimeout(function () {
       		$("ul.topnav li").removeClass('active');
     		}, 100);
		});
	
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		       
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
			
          });

          if ($.browser.msie  && parseInt($.browser.version) == 8) {
          $("ul.topnav li div").mouseleave(function() {
          $(this).css("padding", "0 0");
          });
          }else {}
                
          $("ul.subnav li").hover(function() {
          $(this).find("ul.sub_sub_menu").show();
	  }, function(){
          $(this).find("ul.sub_sub_menu").hide();
	  });
	  

          if ($.browser.msie  && parseInt($.browser.version) == 7) {
          } else {  
	  $("ul.sub_sub_menu").hover(function() {
          $(this).parent('ul.subnav li').addClass('activate');
	  }, function(){
          $(this).parent('ul.subnav li').removeClass('activate');
	  });
	  }

          if ($.browser.msie  && parseInt($.browser.version) == 7) {
          } else {  
	  $("ul.topnav li").hover(function() {
          Cufon.replace('.topnav li span a', {fontFamily: 'Code bold'});
	  }, function(){
          Cufon.replace('.topnav li span a', {fontFamily: 'Code bold'});
	  });
	  }
});
