function yiw_lightbox()
{   
    jQuery('a.thumb').hover(
                            
        function()
        {
            jQuery('<a class="zoom">zoom</a>').appendTo(this).css({
				dispay:'block', 
				opacity:0, 
				height:jQuery(this).children('img').height(), 
				width:jQuery(this).children('img').width(),
				'top':jQuery(this).css('padding-top'),
				'left':jQuery(this).css('padding-left'),
				padding:0}).animate({opacity:0.4}, 500);
        },
        
        function()
        {           
            jQuery('.zoom').fadeOut(500, function(){jQuery(this).remove()});
        }
    );
    
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
        slideshow:5000, 
        autoplay_slideshow:false,
        show_title:false
    });
}

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


	//custom hover js for news box
	
	$("#news-list li").hover(function() {
			$(this).find(".grey_top_empty").addClass("grey_top");
			$(this).find(".grey_middle_empty").addClass("grey_middle");
			$(this).find(".grey_middle_content_empty").addClass("grey_middle_content");
			$(this).find(".grey_bottom_empty").addClass("grey_bottom");
	},function() {
			$(this).find(".grey_top_empty").removeClass("grey_top");
			$(this).find(".grey_middle_empty").removeClass("grey_middle");
			$(this).find(".grey_middle_content_empty").removeClass("grey_middle_content");
			$(this).find(".grey_bottom_empty").removeClass("grey_bottom");
	});

	 // Main Navigation Menu
	$('#primary-menu > ul > li').hover(function() {
			$(this).addClass("hover");
			$(this).prev().addClass("previous");
			$(this).children(".submenu-wrap").stop(true, true).animate({ "height": "show", "opacity": "show" }, 200 );
	},function() {         
			$(this).removeClass("hover");
			$(this).prev().removeClass("previous");
			$(this).children(".submenu-wrap").stop(true, true).animate({ "height": "hide", "opacity": "hide" }, 200 );
			yiw_navigation_cufon();
	});
	
	$('#primary-menu > ul > li:first').hover(function() {
			$("#primary-menu > ul").addClass("previous");
	},function() {
			$("#primary-menu > ul").removeClass("previous");
	});
	
	$(".menu_image img").fadeTo(0,0.7);
	$(".menu_image img").hover(function(evt) {
			$(this).fadeTo(300,7);
	},function(evt) {
			$(this).fadeTo(300,0.7);
	});
	
	$('#primary-menu ul li.normal li').hover(function() {
			$(this).children(".sub-menu").stop(true, true).animate({ "height": "show", "opacity": "show" }, 200 );
	},function() {
			$(this).children(".sub-menu").stop(true, true).animate({ "height": "hide", "opacity": "hide" }, 200 );
	});
	
	// add indicator
	$('#primary-menu > ul > li').each(function(){
		if ( $('.submenu-wrap', this).length != 0 )
			$(this).children('a').append( '<img class="indicator" src="images/icons/arrow-nav-down.png" alt="" />' );
	});
	$('#primary-menu .sub-menu > li').each(function(){
		if ( $('.sub-menu', this).length != 0 )
			$(this).children('a').after( '<span class="sub-indicator"></span>' );
	});

	$('body').removeClass('no_js').addClass('yes_js');  
	
	yiw_lightbox();

    $('a.socials, a.socials-small').tipsy({fade:true, gravity:'s'});
    
    $('.toggle-content:not(.opened), .content-tab:not(.opened)').hide();
    $('.toggle-title').click(function(){
        $(this).next().slideToggle(300);
        $(this).children('span.open-toggle').toggleClass('closed');
        $(this).attr('title', ($(this).attr('title') == 'Close') ? 'Open' : 'Close');
        return false;
    });     
    $('.tab-index a').click(function(){           
        $(this).parent().next().slideToggle(300, 'easeOutExpo');
        $(this).toggleClass('opened');
        $(this).attr('title', ($(this).attr('title') == 'Close') ? 'Open' : 'Close');
        return false;
    });     
    
    $('.tabs-container').yiw_tabs({
        tabNav  : 'ul.tabs',
        tabDivs : '.border-box'
    });
    
    // quick-contact     
    var height_nav = $('.quick-contact-box .nav-box').height() - $('.quick-contact-box .box-info').innerHeight() + $('.quick-contact-box .box-info').height();
    $('.quick-contact-box .box-info').css('min-height', height_nav );      
	
	$('.quick-contact-box .box-info div.panel').hide();
	$('.quick-contact-box .box-info div.panel:eq(0)').show();
		
	if( $('.quick-contact-box .active').length == 0 )
		$('.quick-contact-box .nav-box li:first-child').addClass('active');	
		
    $('.quick-contact-box .nav-box a').click(function(){
		var hash = $(this).attr('href');                        
    	$('.quick-contact-box .active').removeClass('active');
		
		$('.quick-contact-box .box-info div.panel').hide();
		$(hash).fadeIn('slow');
		$(this).parent().addClass('active');	
		//alert(hash);
		
		return false;
	});
	
	// cart
	$('#topbar li.fast-info').hover(
		function()
		{
			$(this).find('.access-info-box').slideDown(300);
		},
		
		function()
		{
			$(this).find('.access-info-box').hide();
		}
	);
	$('#topbar li.fast-info > a').click( function(){ return false; } );
    
    
	
	
	$('.close_msg').live( 'click', function(){
		$(this).parent().remove();
		$('#footer .quick-contact-widget ul').slideDown(500);
		return false;
	});
					
	$('.twitter-container').tweetable({
		id: 'tweets',
		username: 'YIW', 
		time: true, 
		limit: 2, 
		replies: true
	});
	
	
	// autoclean labels
	$elements = $('#footer .quick-contact-widget input, #footer .quick-contact-widget textarea, input.email-newsletter')
    
	$elements.each(function(){
        if( $(this).val() != '' )	
			$(this).prev().css('display', 'none');
    }); 
    $elements.focus(function(){
        if( $(this).val() == '' )	
			$(this).prev().css('display', 'none');
    }); 
    $elements.blur(function(){ 
        if( $(this).val() == '' )	
        	$(this).prev().css('display', 'block');
    });       
	
	//$(".accordion-slider li:not(.accordion-closed)").addClass('accordion-closed');
	//$(".accordion-slider").msAccordion(); 
});          

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

	$('iframe').not('.google-map-frame iframe').each(function() {
	
		var url = $(this).attr("src");
		
		//$(this).attr("src",url+"?wmode=transparent");
	
	});

});

jQuery(document).ready(function($) {                                               
	$(".accordion-slider").hrzAccordion({
						openOnLoad		   : 1,
		handlePosition     : "left",
		completeAction	   : function() {					Cufon.replace('.accordion-slider h5', {fontSize: '20px'});   
			Cufon.replace('ul.accordion-slider p.profile', 	{fontFamily: 'delicious', fontSize: '16px'});       
		}
	});
});  
             

jQuery(document).ready(function($){
    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'pp_default'});
});  

// tabs plugin
(function($) {
    $.fn.yiw_tabs = function(options) {
        // valori di default
        var config = {
            'tabNav': 'ul.tabs',
            'tabDivs': '.containers',
            'currentClass': 'current'
        };      
 
        if (options) $.extend(config, options);
    	
    	this.each(function() {   
        	var tabNav = $(config.tabNav, this);
        	var tabDivs = $(config.tabDivs, this);
        	var activeTab;
        	
            tabDivs.children('div').hide();
    	
    	    if ( $('li.'+config.currentClass+' a', tabNav).length > 0 )
               activeTab = $('li.'+config.currentClass+' a', tabNav).attr('href'); 
        	else
        	   activeTab = $('li:first-child a', tabNav).attr('href');
                        
        	$(activeTab).show().addClass('showing');
            $('a[href="'+activeTab+'"]', tabNav).parents('li').addClass(config.currentClass);
        	
        	$('a', tabNav).click(function(){
        		var id = $(this).attr('href');
        		var thisLink = $(this);
        		
        		$('li.'+config.currentClass, tabNav).removeClass(config.currentClass);
        		$(this).parents('li').addClass(config.currentClass);
        		
        		$('.showing', tabDivs).fadeOut(200, function(){
        			$(this).removeClass('showing');
        			$(id).fadeIn(200).addClass('showing');
        		});
        		
        		return false;
        	});   
        });
    }
})(jQuery);

// gallery
if (jQuery().quicksand) {         

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

		$('.hentry-post').css( { 'min-height': $('.gallery-wrap').height() } );
	
	});

	(function($) {                                     
		
		$.fn.sorted = function(customOptions) {
			var options = {
				reversed: false,
				by: function(a) {
					return a.text();
				}
			};
	
			$.extend(options, customOptions);
	
			$data = jQuery(this);
			arr = $data.get();
			arr.sort(function(a, b) {
	
				var valA = options.by($(a));
				var valB = options.by($(b));
		
				if (options.reversed) {
					return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;				
				} else {		
					return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;	
				}
		
			});
	
			return $(arr);
	
		};
	
	})(jQuery);
	
	jQuery(function($) {
	
		var read_button = function(class_names) {
			
			var r = {
				selected: false,
				type: 0
			};
			
			for (var i=0; i < class_names.length; i++) {
				
				if (class_names[i].indexOf('selected-') == 0) {
					r.selected = true;
				}
			
				if (class_names[i].indexOf('segment-') == 0) {
					r.segment = class_names[i].split('-')[1];
				}
			};
			
			return r;
			
		};
	
		var determine_sort = function($buttons) {
			var $selected = $buttons.parent().filter('[class*="selected-"]');
			return $selected.find('a').attr('data-value');
		};
	
		var determine_kind = function($buttons) {
			var $selected = $buttons.parent().filter('[class*="selected-"]');
			return $selected.find('a').attr('data-value');
		};
	
		var $preferences = {
			duration: 500,
			adjustHeight: 'auto'
		}
	
		var $list = jQuery('.gallery-wrap');
		var $data = $list.clone();
	
		var $controls = jQuery('.gallery-categories');
	
		$controls.each(function(i) {
	
			var $control = jQuery(this);
			var $buttons = $control.find('a');
			var height_list = $list.height();
	
			$buttons.bind('click', function(e) {
	
				var $button = jQuery(this);
				var $button_container = $button.parent();
				var button_properties = read_button($button_container.attr('class').split(' '));      
				var selected = button_properties.selected;
				var button_segment = button_properties.segment;
	
				if (!selected) {  	
					$buttons.parent().removeClass();
					$button_container.addClass('selected-' + button_segment);
	
					var sorting_type = determine_sort($controls.eq(1).find('a'));
					var sorting_kind = determine_kind($controls.eq(0).find('a'));
	
					if (sorting_kind == 'all') {
						var $filtered_data = $data.find('li');
					} else {
						var $filtered_data = $data.find('li.' + sorting_kind);
					}
	
					var $sorted_data = $filtered_data.sorted({
						by: function(v) {
							return $(v).find('strong').text().toLowerCase();
						}
					});
	
					$list.quicksand($sorted_data, $preferences, function () {
							yiw_lightbox();   
							
							var current_height = $list.height();       
				
							$('.hentry-post').animate( { 'min-height':$list.height() }, 300, function(){ Cufon.replace('#portfolio-gallery h6'); } );
							
					});
		
				}
		
				e.preventDefault();
				
			});
		
		}); 
		
	});

}
