//Author: Chris Mooney (http://themeforest.net/user/ChrisMooney)

jQuery.noConflict();
jQuery(document).ready(function($) {

if ($.browser.msie && $.browser.version < 7) return; // Don't execute code if it's IE6 or below cause it doesn't support it.
// Superfish navigation dropdown */
if(jQuery().superfish) {
jQuery( 'ul.nav').superfish({
delay: 200,
animation: {opacity:'show', height:'show'},
speed: 'fast',
dropShadows: false
});
}
// Add first/last classes to menus 
$('ul.nav > li:first-child').addClass('first-item');
$('ul.nav > li:last-child').addClass('last-item');
$('ul.sub-menu > li:first-child').addClass('first-item');
$('ul.sub-menu > li:last-child').addClass('last-item');	
//footer menu
$('ul.nav-footer > li:first-child').addClass('first-item');
$('ul.nav-footer > li:last-child').addClass('last-item');	



// Hover Animations 
function element_hover(){
	jQuery('.button').hover(
		function() {
				jQuery(this).stop().animate({opacity:0.9},200);
			},
			function() {
				jQuery(this).stop().animate({opacity:1},200);
		});
}
jQuery(document).ready(function() {
	if(!jQuery.browser.msie){element_hover();}
	});



//Pretty Photo
$("a[rel^='prettyPhoto']").prettyPhoto({
	social_tools: '',
	});

	 
	 
//Image Preloader	 
$.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);
						}
					}
				}
			};
			
			if(count==0){
				settings.afterShowAll.call(this);
			}else{
				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 || ($.browser.msie && parseInt(jQuery.browser.version, 10) == 9) ){
							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(".image_frame").preloader({
		delay:1000,
		imgSelector:'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);
		}
	});
//Image Preloader End	 
	
//Image Overlay 
function image_overlay() {
jQuery('.image_frame a').hover( function () {
jQuery(this).find('.overlay').stop().fadeTo("fast", 1);
}, function () {
jQuery(this).find('.overlay').stop().fadeTo("fast", 0);
});
}
image_overlay(); 
//Image Overlay End
 








 
//Scroll Window Up
	$('.top').click(
		function (e) {
			$('html, body').animate({scrollTop: '0px'}, 500);
		}
    );



//Contact Form
$('#contactform').submit(function(){
	
		var action = $(this).attr('action');
		
		$("#message").slideUp(750,function() {
		$('#message').hide();
		
 		$('#submit')
			.after('<img src="images/ajax-loader.gif" class="loader" />')
			.attr('disabled','disabled');
		
		$.post(action, { 
			name: $('#name').val(),
			email: $('#email').val(),
			subject: $('#subject').val(),
			comments: $('#comments').val(),
			verify: $('#verify').val()
		},
			function(data){
				document.getElementById('message').innerHTML = data;
				$('#message').slideDown('slow');
				$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
				$('#submit').removeAttr('disabled'); 
				if(data.match('success') != null) $('#contactform').slideUp('slow');
				
			}
		);
		
		});
		
		return false; 
	
	});
 
 
 
	 
});	
