// JavaScript Document
$(document).ready(function(){ 
	
	jQuery('.fotogall').kriesi_image_preloader({delay:400});	// activates preloader for non-slideshow images
	$('#show-settings-link').click(function(){
	    $("#screen-options-wrap").slideToggle('slow');
	});


$('#keyword').focus(function(e) {
			e.preventDefault();
			var keyword = $(this).val();
					   if ((keyword=="Inserisci termine di ricerca...")){
						   $('#keyword').val("")
						   }		
      						});
$('#keyword').blur(function(e) {
			e.preventDefault();
			var keyword = $(this).val();
					   if ((keyword=="")){
						   $('#keyword').val("Inserisci termine di ricerca...")
						   }		
      						});

}); 



(function($)
{
	$.fn.kriesi_image_preloader = function(options) 
	{
		var defaults = 
		{
			repeatedCheck: 500,
			fadeInSpeed: 1000,
			delay:600,
			callback: ''
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var imageContainer = jQuery(this),
				images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
				imagesToLoad = images.length;				
				
				imageContainer.operations =
				{	
					preload: function()
					{	
						var stopPreloading = true;
						
						images.each(function(i, event)
						{	
							var image = $(this);
							
							
							if(event.complete == true)
							{	
								imageContainer.operations.showImage(image);
							}
							else
							{
								image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
							}
							
						});
						
						return this;
					},
					
					showImage: function(image)
					{	
						imagesToLoad --;
						if(image.data.currentImage != undefined) { image = image.data.currentImage;}
												
						if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
												 
						if(imagesToLoad == 0)
						{
							if(options.delay > 0)
							{
								images.each(function(i, event)
								{	
									var image = $(this);
									setTimeout(function()
									{	
										image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
									},
									options.delay*(i+1));
								});
								
								if(options.callback != '')
								{
									setTimeout(options.callback, options.delay*images.length);
								}
							}
							else if(options.callback != '')
							{
								(options.callback)();
							}
							
						}
						
					}

				};
				
				imageContainer.operations.preload();
		});
		
	}
})(jQuery);

		
	
	
function showText(text) {
	return unescape(text);
}
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}






var template_url = '';
	
	
	//IMAGE PRELOADERS
	jQuery(function(){
		jQuery(".galleries,.portfolio-3c,.portfolio-2c,.portfolio-1c,.portfolio-1c,.blog-small-image,.blog-medium-image,.blog-large-image,.feature_boxes,.small_image,.medium_image,.large_image").preloader({
			'temp_url' : template_url
		});
	});
	
	
	
	jQuery(document).ready(function() {		
				
		//HOMEPAGE 1 TIME PRELOADER
		jQuery(window).load(
			function() {			
					//BACKGROUND SLIDER		
												
				jQuery('#hp_preloader').delay(1000).animate({'opacity':'0'},1400,function(){
					jQuery(this).remove();
					
										
				});				
			}
		);		
						
				
				
				
		jQuery('#menu .menu-item').hover(
			function(){
				jQuery(this).has('ul').find('ul').stop(true,true).delay(200).slideDown('slow');
			},
			function(){
				jQuery(this).has('ul').find('ul').stop(true,true).slideUp('slow');
			}
		);
		
		
		
				
		
		if(jQuery.browser.msie){
			if(jQuery.browser.version > '8.0'){				
				jQuery(".imghover_gallery, .imghover_3c_pfolio, .imghover_2c_pfolio, .imghover_1c_pfolio, a .imghover_small, a .imghover_medium, a .imghover_large, a .imghover_small_blog, a .imghover_medium_blog, a .imghover_large_blog").hover(
					function(){
						//hide the rest						
						jQuery(this).css('display','none').css('background-image','url(/images/image_overlay.png)').fadeTo('fast',1.0);
					},
					function(){
						jQuery(this).fadeTo('fast',0.0);
					}
				);
			}
		}else{
			jQuery(".imghover_gallery, .imghover_3c_pfolio, .imghover_2c_pfolio, .imghover_1c_pfolio, a .imghover_small, a .imghover_medium, a .imghover_large, a .imghover_small_blog, a .imghover_medium_blog, a .imghover_large_blog").hover(
				function(){
					//hide the rest						
					jQuery(this).css('display','none').css('background-image','url(/images/image_overlay.png)').fadeTo('fast',1.0);
				},
				function(){
					jQuery(this).fadeTo('fast',0.0);
				}
			);
		}
		
		
				//QUICKSAND
		// get the action filter option item on page load
		  var $filterType = jQuery('.pf_categories li.active a').attr('class');
			
		  // get and assign the portfolio-3c element to the
			// $holder varible for use later
		  var $holder = jQuery('ul.portfolio-3c,ul.portfolio-2c,ul.portfolio-1c');

		  // clone all items within the pre-assigned $holder element
		  var $data = $holder.clone();

		  // attempt to call Quicksand when a filter option
			// item is clicked
			jQuery('.pf_categories li a').click(function(e) {
				// reset the active class on all the buttons
				jQuery('.pf_categories li').removeClass('active');
				
				// assign the class of the clicked filter option
				// element to our $filterType variable
				var $filterType = jQuery(this).attr('class');
				jQuery(this).parent().addClass('active');
				
				if ($filterType == 'all') {
					// assign all li items to the $filteredData var when
					// the 'All' filter option is clicked
					var $filteredData = $data.find('li');
				} 
				else {
					// find all li elements that have our required $filterType
					// values for the data-type element
					var $filteredData = $data.find('li[data-type=' + $filterType + ']');
				}
				
				// call quicksand and assign transition parameters
				$holder.quicksand($filteredData, {
					duration: 800,
					easing: 'easeInOutQuad'
				}, function(){
					//REINIT ALL JQ STUFF!
				
					//preloader handle					
					jQuery('.portfolio-3c li img,.portfolio-2c li img,.portfolio-1c li img').each(function(){
						jQuery(this).css({'opacity':'1','visibility':'visible'});
					});
					
					
					
					
					jQuery('.fancybox').fancybox();
					jQuery('.fancybox_iframe').fancybox(
						{
							'width'				: '75%',
							'height'			: '75%',
							'autoScale'     	: false,
							'type'				: 'iframe'
						}
					);
					jQuery('.fancybox_embed').fancybox(
						{
							'hideOnContentClick': true
						}
					);
					var vid_id = jQuery('.fancybox_flv').attr('href');
					jQuery('.fancybox_flv').fancybox(
						{				
							'href'	:	'/swf/player_flv_maxi.swf',
							'autoScale'     	: true,
							'type'				: 'swf',
							'swf'			: {
							'FlashVars'		: 'showvolume=1&amp;buttonovercolor=d3aa66&amp;sliderovercolor=d3aa66&amp;loadingcolor=ffffff&amp;autoplay=1&amp;flv='+vid_id
							}
						}
					);
					
					
					if(jQuery.browser.msie){
						if(jQuery.browser.version > '8.0'){				
							jQuery(".imghover_gallery, .imghover_3c_pfolio, .imghover_2c_pfolio, .imghover_1c_pfolio, a .imghover_small, a .imghover_medium, a .imghover_large, a .imghover_small_blog, a .imghover_medium_blog, a .imghover_large_blog").hover(
								function(){
									//hide the rest						
									jQuery(this).css('display','none').css('background-image','url(/images/image_overlay.png)').fadeTo('fast',1.0);
								},
								function(){
									jQuery(this).fadeTo('fast',0.0);
								}
							);
						}
					}else{
						jQuery(".imghover_gallery, .imghover_3c_pfolio, .imghover_2c_pfolio, .imghover_1c_pfolio, a .imghover_small, a .imghover_medium, a .imghover_large, a .imghover_small_blog, a .imghover_medium_blog, a .imghover_large_blog").hover(
							function(){
								//hide the rest						
								jQuery(this).css('display','none').css('background-image','url(/images/image_overlay.png)').fadeTo('fast',1.0);
							},
							function(){
								jQuery(this).fadeTo('fast',0.0);
							}
						);
					}					
								
				});
				return false;
			});
		
		
				
		
		//FANCYBOX
		jQuery('.fancybox').fancybox();
		jQuery('.fancybox_iframe').fancybox(
			{
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'     	: false,
				'type'				: 'iframe'
			}
		);
		jQuery('.fancybox_embed').fancybox(
			{
				'hideOnContentClick': true
			}
		);
		var vid_id = jQuery('.fancybox_flv').attr('href');
		jQuery('.fancybox_flv').fancybox(
			{				
				'href'	:	'/swf/player_flv_maxi.swf',
				'autoScale'     	: true,
				'type'				: 'swf',
				'swf'			: {
			   	'FlashVars'		: 'showvolume=1&amp;buttonovercolor=d3aa66&amp;sliderovercolor=d3aa66&amp;loadingcolor=ffffff&amp;autoplay=1&amp;flv='+vid_id
				}
			}
		);	
						
	});
	
$(function(){
$('.hover').hover(function() {
$(this).stop().animate({'opacity': 0.6});
},function() {
$(this).stop().animate({'opacity': 1});
}); 
links = 'a:not(.button, .no-effect, #logo a, #pagepanner a, .rightbanner a, .notif a, .post h2 a, .zoom)';
$(links).hover(function() {
$(this).stop().animate({'opacity': 0.7}, 'fast');
},function() {
$(this).stop().animate({'opacity': 1}, 'fast');
});
});
