jQuery(document).ready(function() {
	$('#navigation ul.menu').supersubs({ 
			minWidth:    10,
			maxWidth:    20, 
            extraWidth:  1    
		}).superfish({ hoverClass: "sfHover", speed: 'slow', dropShadows: true, delay: 0, animation: {height:'show'}});
Cufon.replace('#navigation  .menu>li>a, #footer h2', {
		hover: true,
		textShadow: '-1px -1px rgba(0, 0, 0, 0.3), 1px 1px rgba(255, 255, 255, 0.2)'
	});
	Cufon.replace('#intro h2', {
		hover: true,
		textShadow: '1px 1px rgba(0, 0, 0, 0.3)'
	});
	Cufon.replace('.posttitle h3, .posttext h3, .posttext h1, .posttext h2, .posttext h4, .posttext h5, .posttext h6, #frontpagewrapper h2', {
		hover: true
	});
	if(!jQuery.browser.msie){
		hoverbutton();
		jQuery(".social a").stop().fadeTo("medium", 0.7); 
		hoverbuttonReverse();
	} 
	$('a[href$="top"]').click( function() {
		$.scrollTo( $('#header'), {speed:700} );
	});
	jQuery(".social a, #shareicons a").simpletooltip();
	jQuery(".tabs_container").each(function(){
		jQuery("ul.tabs",this).tabs("div.panes > div", {tabs:'li',effect: 'fade', fadeOutSpeed: -400});
	});
	jQuery(".toggle_body").hide(); 

	jQuery("h4.toggle").toggle(function(){
		jQuery(this).addClass("toggle_active");
		}, function () {
		jQuery(this).removeClass("toggle_active");
	});
	
	jQuery("h4.toggle").click(function(){
		jQuery(this).next(".toggle_body").slideToggle();

	});
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'facebook',slideshow:5000});
	var enable_image_hover = function(image){
		if(image.is(".portfolio")){
			if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {} else {
				if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) {
					image.hover(function(){
						jQuery(".image_overlay",this).css("visibility", "visible");
					},function(){
						jQuery(".image_overlay",this).css("visibility", "hidden");
					}).children('img').after('<span class="image_overlay"></span>');
				}else{
					image.hover(function(){
						jQuery(".image_overlay",this).animate({
							opacity: '1'
						},"fast");
					},function(){
						jQuery(".image_overlay",this).animate({
							opacity: '0'
						},"fast");
					}).children('img').after(jQuery('<span class="image_overlay"></span>').css({opacity: '0',visibility:'visible'}));
				}
			}
		}		
	}

	
	jQuery(".galleryportfolio3, .galleryportfolio2, .galleryportfolio4").preloader({
		delay:200,
		imgSelector:'.imgbg img',
		beforeShow:function(){
			jQuery(this).closest('.image_frame').addClass('preloading');
		},
		afterShow:function(){
			var image = jQuery(this).closest('.image_frame').removeClass('preloading').children("a");
			enable_image_hover(image);
		}
	});
	// Frontpage Widget Height Match
	var maxHeight = 0;
	$(".module").each(function(){
		  if ($(this).height() > maxHeight) {
				maxHeight = $(this).height();
		  }
	});
	$(".module").height(maxHeight);
	$(".module").innerHeight(maxHeight);
	$(".module").css({'min-height': maxHeight}); 

	// Galleries Height Match
	var galleryHeight = 0;
	$(".galleryportfolio2 ul li, .galleryportfolio3 ul li, .galleryportfolio4 ul li").each(function(){
		  if ($(this).height() > galleryHeight) {
				galleryHeight = $(this).height();
		  }
	});
	$(".galleryportfolio2 ul li, .galleryportfolio3 ul li, .galleryportfolio4 ul li").height(galleryHeight);
});
function hoverbutton(){

jQuery('#searchsubmit, #shareicons img, .magnifier a').hover(function(){
	jQuery(this).stop().fadeTo("medium", 0.6);
	},function(){
	jQuery(this).stop().fadeTo("slow", 1.0); 
	});	
}
function hoverbuttonReverse(){
	jQuery(".social a").hover(function(){
		jQuery(this).stop().fadeTo("fast", 1);
		},function(){
		jQuery(this).stop().fadeTo("medium", 0.7); 
		});	
}
(function($){ $.fn.simpletooltip = function(){
	return this.each(function() {
		var text = $(this).attr("title");
		$(this).attr("title", "");
		if(text != undefined) {
			$(this).hover(function(e){
				var tipX = e.pageX + 12;
				var tipY = e.pageY + 12;
				$(this).attr("title", ""); 
				$("body").append("<div id='simpleTooltip' style='position:absolute; z-index: 100; display: none;'>" + text + "</div>");
				if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
				else var tipWidth = $("#simpleTooltip").width()
				$("#simpleTooltip").width(tipWidth);
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			}, function(){
				$("#simpleTooltip").remove();
				$(this).attr("title", text);
			});
			$(this).mousemove(function(e){
				var tipX = e.pageX - 0;
				var tipY = e.pageY - 40;
				var tipWidth = $("#simpleTooltip").outerWidth(true);
				var tipHeight = $("#simpleTooltip").outerHeight(true);
				if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
				if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			});
		}
	});
}})(jQuery);
(function($) {

	$.fn.preloader = function(options) {
		var settings = $.extend({}, $.fn.preloader.defaults, options);


		return this.each(function() {
			settings.beforeShowAll.call(this);
			var imageHolder = $(this);
			
			var images = imageHolder.find(settings.imgSelector).css({opacity:0, visibility:'hidden'});	
			var count = images.length;
			var showImage = function(image,imageHolder){
				if(image.data.source != undefined){
					imageHolder = image.data.holder;
					image = image.data.source;	
				};
				
				count --;
				if(settings.delay <= 0){
					image.css('visibility','visible').animate({opacity:1}, settings.animSpeed, function(){settings.afterShow.call(this)});
				}
				if(count == 0){
					imageHolder.removeData('count');
					if(settings.delay <= 0){
						settings.afterShowAll.call(this);
					}else{
						if(settings.gradualDelay){
							images.each(function(i,e){
								var image = $(this);
								setTimeout(function(){
									image.css('visibility','visible').animate({opacity:1}, settings.animSpeed, function(){settings.afterShow.call(this)});
								},settings.delay*(i+1));
							});
							setTimeout(function(){settings.afterShowAll.call(imageHolder[0])}, settings.delay*images.length+settings.animSpeed);
						}else{
							setTimeout(function(){
								images.each(function(i,e){
									$(this).css('visibility','visible').animate({opacity:1}, settings.animSpeed, function(){settings.afterShow.call(this)});
								});
								setTimeout(function(){settings.afterShowAll.call(imageHolder[0])}, settings.animSpeed);
							}, settings.delay);
						}
					}
				}
			};
			

			images.each(function(i){
				settings.beforeShow.call(this);
				
				image = $(this);
				
				if(this.complete==true){
					showImage(image,imageHolder);
				}else{
					image.bind('error load',{source:image,holder:imageHolder}, showImage);
					if($.browser.opera){
						image.trigger("load");//for hidden image
					}
				}
			});
		});
	};


	//Default settings
	$.fn.preloader.defaults = {
		delay:1000,
		gradualDelay:true,
		imgSelector:'img',
		animSpeed:500,
		beforeShowAll: function(){},
		beforeShow: function(){},
		afterShow: function(){},
		afterShowAll: function(){}
	};
})(jQuery);
