jQuery(document).ready(function() {

    jQuery('#slider').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed: 3000,
		timeout: 8500,
		pager: '#nav'
	});
									
	
	// hover effects on portfolio type 2 images
	jQuery('.port2-list li').mouseenter(function(e) {
		jQuery(this).find('.hframe, .hframe-controls').stop(true, true).fadeTo(300, 0.75);
		
	}).mouseleave(function(e) {
		jQuery(this).find('.hframe, .hframe-controls').stop(true, true).fadeTo(300, 0);
		
	});	

		 
	// picture hover zoom
	jQuery('.zoom-parent').mouseenter(function(e) {
		jQuery(this).find('.image-zoom').stop(true, true).fadeTo(400, 1);
	}).mouseleave(function(e) {
		jQuery(this).find('.image-zoom').stop(true, true).fadeTo(400, 0);
	});		
			 
	//Contact Form
	jQuery('form#contactForm').submit(function() {
		
		//jQuery('form#contact_form .error').remove();
		var hasError = false;
		jQuery('.requiredContact').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text();
				//jQuery(this).parent().append('<div class="c-error">Mandatory field</div>');
				jQuery(this).addClass('inputError');
				hasError = true;
			} else if(jQuery(this).hasClass('cEmail')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					var labelText = jQuery(this).prev('label').text();
					//jQuery(this).parent().append('<div class="c-error">Invalid email address</div>');
					jQuery(this).addClass('inputError');
					hasError = true;
				}
			}
		});
	
		if(!hasError) {
			return true;
		}
		return false;
	
	});

	// superfish fix
	jQuery(window).unload(function(){
		jQuery('ul.sf-menu li.current').hideSuperfishUl();
	});

	
	// Toggle content script
	jQuery(".toggle-content").hide(); 
	
	jQuery("h6.toggle").toggle(function(){
		jQuery(this).addClass("active");
		}, function () {
		jQuery(this).removeClass("active");
	});
	
	jQuery("h6.toggle").click(function(){
		jQuery(this).next(".toggle-content").slideToggle();
	});
	
	// pretty photo
	jQuery("a[rel^='prettyPhoto']").fancybox();			
	
	// applies equal height script on half box divs
	equalHeight(jQuery(".hb-body"));
	
	// fixes the ie png transparency
/*	var i;
	for (i in document.images) {
		if (document.images[i].src) {
			var imgSrc = document.images[i].src;
			if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
				document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
			}
		}
	}*/
  	

});

function equalHeight(group) {
  tallest = 0;
  group.each(function() {
    thisHeight = jQuery(this).height();
    if(thisHeight > tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
}


