jQuery(function(){

	// Add the "&raquo;" to the menu and fix spacings
	jQuery(".menu-header ul li").each(function(){
		if(jQuery(this).children('ul').length>0){
			jQuery(this).find('a:first').append(' &raquo;');
		}
	});
		
		
	// This is the CUFON FONT target. All elements are targeted individually for complete control. Delete or add as you wish., 
   Cufon.replace("h1, h2, h3, h4, h5, h6, span.port_4_title, a.cycle_cta, blockquote, .portfolio_item_4_col span.portfolio_title, a.blog_button, a.tagline_button, .testimonial_quote", {hover: true});
   		   		
				
});


jQuery(document).ready(function() {
								
	// Sliding Links
	// ------------------------------------------------------------
	jQuery('.footer_widget ul li').each(function() {
		var ti_def = jQuery(this).css("text-indent");
		var pr_def = jQuery(this).css("padding-right");
		
		jQuery(this).hover(
			function() {
				jQuery(this).animate({
					textIndent:  parseInt(ti_def) + 3 + "px"
				}, 120);
			},
			function() {
				jQuery(this).animate({
					textIndent: ti_def
				}, 120);
			}
		);
		
	});
	
	
	// Sticky footer
	// ------------------------------------------------------------
	jQuery('#main_content_two_col, #homepage_content').css("padding-bottom", jQuery('#footer').height()+"px");
	jQuery('#footer').css("height", jQuery('#footer').height()+"px");
								
	
	// Slideshow
	// ------------------------------------------------------------
	if ($(".cycle_right").length) {
		jQuery(".cycle_right").cycle({
			fx:'fade',
			speed:2000, 
			pause:true, 
			timeout:7000, 
			pager:"#cycle_nav"
			//	before: stopVideo,
			//	after: stopVideo
		});
	}


	// Shortcode animation - Show/Hide
	jQuery("a.show_hide").toggle(
		function(){
			jQuery(this).parent("div").children("div").fadeIn(300);
		},
		function() {
			jQuery(this).parent("div").children("div").fadeOut(300);
		}
	);
   
   
	//Get Rid of Margin on 3th Homepage Box and Footer widgets
	jQuery("#homepage_icon_boxes div:nth-child(3), #homepage_icon_boxes div:nth-child(3)").css("margin-right", "0px");
	jQuery("#footer_inner div:nth-child(3)").css("margin-right", "0px");

	
	//Menu animation
	jQuery(".menu-header ul li").each(function() {
		var li_width = jQuery(this).width();    //Get the width of parent li element				
		var centred_width = (( 108 - (li_width / 2)) * -1 );    //Calculate displacement for background span image			
		var centred_width2 = (( 82 - (li_width / 2)) * -1 );    //Calculate displacement for ul Dropdown		
		jQuery(this).children("ul").hide().css("left", centred_width2 + "px");		//Alter absolute left property (centre)				
		
		jQuery(this).hover(
			function(){			
				jQuery(this).prepend(jQuery("<span></span>"));	  //Inject the background image			
				jQuery(".menu-header ul li ul li span").remove();	  //Remover the image from drop downs	
				jQuery(this).children("span").css("left", centred_width + "px");    //Alter absolute left property (centre)				
				jQuery(".menu-header ul li ul li ul").css("left", "163px");    //Alter absolute left property of dropdown level 3				
				if (jQuery.browser.msie) {
					jQuery(this).children("span:nth-child(1)").stop().show(); //Fade in the background image
				} else {
					jQuery(this).children("span:nth-child(1)").stop().fadeTo(400, 0.9); //Fade in the background image					
				}
				//jQuery(this).children("a").stop().fadeTo(300, 1); // Fade in text fully
				jQuery(this).children("ul").stop(true, true).slideDown(200, function() {
					jQuery(this).css("display", "block");
				});
			},
			function(){
				if (jQuery.browser.msie) {
					jQuery(this).children("span:nth-child(1)").stop().remove(); //Fade in the background image
				} else {
					jQuery(this).children("span:nth-child(1)").stop().fadeOut(400, function() {jQuery(this).remove();});
					//jQuery(this).children("a").stop().fadeTo(300, 0.7);
				}
				jQuery(this).children("ul").fadeOut(300);
					
			}
		)
	});
	
	
	// Lightbox
	// ------------------------------------------------------------
	jQuery('.content').find(
		'a[href$=jpg], '  + 
		'a[href$=jpeg], ' + 
		'a[href$=png], '  + 
		'a[href$=gif], '  +
		'a[href*="vimeo.com"], '   + 
		'a[href*="youtube.com"], ' +
		'a[href$=".swf"], ' +
		'a[href$=".mov"]').each(function()
  		{
			if(!jQuery(this).attr('rel') != undefined && !jQuery(this).attr('rel') != '' && !jQuery(this).hasClass('no-lightbox')) {
				jQuery(this).attr('rel', 'lightbox[content]');
			}
		}
	);


	if($.isFunction($.fn.prettyPhoto)) {
		$("a[rel^='lightbox']").prettyPhoto({
			theme:'pp_default', // light_rounded / dark_rounded / light_square / dark_square / facebook / pp_default
			overlay_gallery: false // If set to true, a gallery will overlay the fullscreen image on mouse over
		});
	}


	// Lightbox Zoom overlay
	// ------------------------------------------------------------
	jQuery("a[rel^='lightbox'] img").each(function() {
	  var img  = jQuery(this);
	  var link = jQuery(this).parent();
	  var bg   = jQuery("<span class='lightbox-image'></span>").appendTo(link);

		link.bind('mouseenter', function() {
			var margin_top     = parseInt(img.css("margin-top"));
			var margin_bottom  = parseInt(img.css("margin-bottom"));
			var padding_left   = parseInt(img.css("padding-left"));
			var padding_top    = parseInt(img.css("padding-top"));
			var padding_right  = parseInt(img.css("padding-right"));
			var padding_bottom = parseInt(img.css("padding-bottom"));
			var border_left    = parseInt(img.css("border-left-width"));
			var border_top     = parseInt(img.css("border-top-width"));
			var border_right   = parseInt(img.css("border-right-width"));
			var border_bottom  = parseInt(img.css("border-bottom-width"));
			var width    = img.width() + padding_left + padding_top + border_left + border_right;
			var height   = img.height() + margin_top + margin_bottom + padding_top + padding_bottom + border_top + border_bottom;
			var position = img.position();
			bg.css({ width:width, height:height, top:position.top, left:position.left });
		});
    
		link.hover(
			function() { img.stop().animate({ opacity: 0.5 }, 200); },
			function() { img.stop().animate({ opacity: 1 }, 200); }
		); 
    });
	
	
	
	// Portfolio 4 Column Animations
	jQuery(".portfolio_item_4_col").hover(
		function(){
		jQuery(this).children("a.frame").stop().animate({ top: "-15px"}, 300 );
		jQuery(this).children(".portfolio_item_4_col span.portfolio_shadow").stop().animate({ bottom: "-7px"}, 300 );
		jQuery(this).children("div.portfolio_item_4_col.description span.portfolio_shadow").stop().animate({ top: "154px"}, 300 );
		jQuery(this).children("a.frame").children("span.portfolio_loading").children("img").stop(true, true).fadeOut(800);
		},
		function(){
		jQuery(this).children("a.frame").stop().animate({ top: "0px"}, 300 );
		jQuery(this).children(".portfolio_item_4_col span.portfolio_shadow").stop().animate({ bottom: "0px"}, 300 );
		jQuery(this).children("div.portfolio_item_4_col.description span.portfolio_shadow").stop().animate({ top: "147px"}, 300 );
		jQuery(this).children("a.frame").children("span.portfolio_loading").children("img").stop(true, true).fadeIn(800);		
		}
	);
	

});	
/*
jQuery(document).ready(function(){	
	
	//The Colourbox Modal Window is initiated here 	
	jQuery(".colourbox-image").colorbox(); //image
	jQuery(".portfolio-modal-anchor").colorbox({iframe:true, innerWidth:1030, innerHeight:560}); //galleria
	jQuery(".video-modal-anchor").colorbox({iframe:true, innerWidth:890, innerHeight:500}); //video

});
*/
