//Cufon font replace script
Cufon.replace('h1,h2,h3,h4,h5,h6,#footer_box_title');


//Image hover effects		
$(document).ready(function(){									
	var thumbs = $("ul li img");		
	
	for (var i = 0, ii = thumbs.length; i < ii; i++){
		if (thumbs[i].title && thumbs[i].title.length > 0)
		{			
			var imgtitle = thumbs[i].title;		
			$(thumbs[i]).wrap('<div class="wrapper" />').				
			after('<div class=\'caption\'>' + imgtitle + '</div>').
			removeAttr('title');
										
		}					
	}
				
$('.wrapper').hover(
	function(){
		$(this).find('img').animate({opacity: ".6"}, 300);		
		$(this).find('.caption').animate({top:"-124px"}, 300);			
	}, 
	function(){
		$(this).find('img').animate({opacity: "1"}, 300);					
		$(this).find('.caption').animate({top:"50px"}, 1000);
	}		
	);			
});


// Main menu sub nav
jQuery(function(){
	jQuery('ul.sf-menu').superfish();
});


//Image NivoSlider script
	$(window).load(function() {
		$('#slider').nivoSlider({
			effect:'fold', //Specify sets like: 'fold,fade,sliceDown'
			slices:15,
			animSpeed:500, //Slide transition speed
			pauseTime:5000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:true, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:true, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
	      	controlNavThumbsFromRel:false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:false, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.6, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){} //Triggers after all slides have been shown
		});
	});

	
// Input Placeholder for All Browsers
	$(document).ready(function(){
		$('[placeholder]').focus(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
				input.removeClass('placeholder');
			}
			}).blur(function() {
				var input = $(this);
				if (input.val() == '' || input.val() == input.attr('placeholder')) {
					input.addClass('placeholder');
					input.val(input.attr('placeholder'));
				}
			}).blur().parents('form').submit(function() {
			$(this).find('[placeholder]').each(function() {
				var input = $(this);
					if (input.val() == input.attr('placeholder')) {
					input.val('');
				}
			})
		});
	});			
		
		
//Fancybox image script	
$(document).ready(function() {
			/*
			*   Examples - images
			*/

			$("a#example1").fancybox();

			$("a#example2").fancybox({
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a#example3").fancybox({
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'	
			});

			$("a#example4").fancybox({
				'opacity'		: true,
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'none'
			});

			$("a#example5").fancybox();

			$("a#example6").fancybox({
				'titlePosition'		: 'outside',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.9
			});

			$("a#example7").fancybox({
				'titlePosition'	: 'inside'
			});

			$("a#example8").fancybox({
				'titlePosition'	: 'over'
			});

			$("a[rel=W3Industry]").fancybox({
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

			/*
			*   Examples - various
			*/

			$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});

			$("#various2").fancybox();

			$("#various3").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

			$("#various4").fancybox({
				'padding'			: 0,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		});
		
		
//Zoom image	
$(function(){
	$(".zoom a").append("<span></span>");
	$(".zoom a").hover(function(){
		$(this).children("img").stop(true, true).animate({opacity:0.7},300);
		$(this).children("span").stop(true, true).fadeIn(300);
	},function(){
		$(this).children("img").stop(true, true).animate({opacity:1},250);
		$(this).children("span").stop(true, true).fadeOut(250);
	});
});		


//Preloading gallery images 
$(function () {
	//$('.preload').hide();//hide all the images on the page
	$('.play,.magnifier').css({opacity:0});
	$('.preload').css({opacity:0});
	$('.preload').addClass("animated");
	$('.play,.magnifier').addClass("animated_icon");
});


var i = 0;//initialize
var cint=0;//Internet Explorer Fix
$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	var cint = setInterval("PreImage(i)",50);//500 is the fade in speed in milliseconds
});

function PreImage() {
	var images = $('.preload').length;//count the number of images on the page
	if (i >= images) {// Loop the images
		clearInterval(cint);//When it reaches the last image the loop ends
	}
	//$('.preload:hidden').eq(i).fadeIn(500);//fades in the hidden images one by one
	$('.animated_icon').eq(0).animate({opacity:1},{"duration": 500});
	$('.animated').eq(0).animate({opacity:1},{"duration": 300});
	$('.animated').eq(0).removeClass("animated");
	$('.animated_icon').eq(0).removeClass("animated_icon");
	i++;//add 1 to the count
}
