$("document").ready(function() {



	// DROPDOWN MENU

	

	$(".header ul.nav li").hover(function(){

	

	    $(this).addClass("hover");

	    $('ul:first',this).css('visibility', 'visible');

	

	}, function(){

	

	    $(this).removeClass("hover");

	    $('ul:first',this).css('visibility', 'hidden');

	

	});	



	// CUFON - font replacement



	// Cufon.replace('.featured .item p span, h3, h4, .subpage .featured h2, ul.items-nav li a', { hover: 'true' });

	

	// FACYBOX 

	

	$("a[rel*=facybox]").facybox();



	// HOMEPAGE SLIDESHOW

	

	$("div.item-wrap") 

	.before('<div class="featured-nav">') 

	.cycle({ 

	    fx:     'fade',  

	    timeout: 4000, 

	    pager:  '.featured-nav',

	    cleartype: true, 

	    cleartypeNoBg: true

	});



	// CONTENT SLIDESHOW (content slideshow on the home page)

	

	$(function() {

		var contentWrapper = $('.main > .tab');

		// only show the first item, hide the rest

		contentWrapper.hide().filter(':first').show();

		

		$('.main ul.tabs-nav li a').click(function () {

		

		    // check if this item doesn't have class "current"

		    // if it has class "current" it must not execute the script again

		    if (this.className.indexOf('current') == -1){

		    	contentWrapper.hide();

		    	contentWrapper.filter(this.hash).fadeIn(500);

		    	$('.main ul.tabs-nav li a').removeClass('current');

		    	$(this).addClass('current');

		    }

		    return false;

		});

	});

	

	// ABOUS US SLIDESHOW (content slideshow on the about page)

	

	$(function() {

		var contentWrapper = $('.main > .item');

		// only show the first item, hide the rest

		contentWrapper.hide().filter(':first').show();

		

		$('ul.items-nav li a').click(function () {

		

		    // check if this item doesn't have class "current"

		    // if it has class "current" it must not execute the script again

		    if (this.className.indexOf('current') == -1){

		    	contentWrapper.hide();

		    	contentWrapper.filter(this.hash).fadeIn(500);

		    	$('ul.items-nav li a').removeClass('current');

		    	$(this).addClass('current');

		    }

		    return false;

		});

	});

	

	// GALLERIA PLUGIN - portfolio single 

	

	$('ul.galleria').galleria({

		history   : false, // activates the history object for bookmarking, back-button etc.

		clickNext : true, // helper for making the image clickable

		insert    : undefined, // the containing selector for our main image. 

		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes

						

						// fade in the image & caption

						if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) {

							image.css('display','none').fadeIn(1000);

						}

						caption.css('display','none').fadeIn(1000);

						

						// fetch the thumbnail container

						var _li = thumb.parents('li');

						

						// fade out inactive thumbnail

						_li.siblings().children('img.selected').fadeTo(500,0.3);

						

						// fade in active thumbnail

						thumb.fadeTo('fast',1).addClass('selected');

						

						// add a title for the clickable image

						image.attr('title','Next image >>');

					},		

		onThumb : function(thumb) { // thumbnail effects goes here

						

						// fetch the thumbnail container

						var _li = thumb.parents('li');

						

						// if thumbnail is active, fade all the way.

						var _fadeTo = _li.is('.active') ? '1' : '0.3';

						

						// fade in the thumbnail when finnished loading

						thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);

						

						// hover effects

						thumb.hover(

							function() { thumb.fadeTo('fast',1); },

							function() { _li.not('.active').children('img').fadeTo('fast',0.3); }

						)

					}						

	});

		

	// CONTACT FORM 

			

	$('#contactform').ajaxForm({

	   	target: '#error',

	   	beforeSubmit: function() {	

	   		$('#error span').remove();

			$('#error').append('<p class="loading">Sending your message...</p>');

		},

		success: function() {

			$('#error p.loading').fadeOut();

			$('#error').fadeIn('slow');

		}

	});	

	

	// CSS ENCHANCEMENTS 

	

	$("ul.gallery li:nth-child(3n+0), ul.posts li:nth-child(2n+0), ul.portfolio li:nth-child(3n+0)").css("margin-right", "0");

	$("ul.categories li:nth-child(2n+0)").css("margin-left", "30px");

	

});



// triggering the galleria plugin on load 



$("document").ready(function() {

    setTimeout(function() {

        $("ul.galleria li:first-child img").trigger('click');

    },3000);

});





// Image loader

function imageLoader() {

	

    $('.loader').each(function () {

					  

        var loader = $(this);

        var pathToImage = loader.attr('title');

        var img = new Image();

	  

        $(img).css("opacity", "0.0").load(function () {

								    

            loader.append(this).removeAttr('title');

		

            $(this).css("margin", "0px").css("opacity", "0.0").animate({

											     

                opacity: 1.0

		    

            },400, function () {

			

                loader.css({ "background-image": "none", "background-color": "transparent" });

		    

            });

		

        }).attr('src', pathToImage);

	  

    });

    

}



$("document").ready(function() {

    imageLoader();

});




