/**
 * Javascript - jQuery enabled
 * 
 * @package WPFramework
 * @subpackage Media
 */

/* Example jQuery
jQuery(document).ready(function($) {
	alert('jQuery + screen.js is loaded and ready to go!');
});
*/

jQuery(document).ready(function(){
	jQuery('div.footer').positionFooter();
	if(jQuery('ul.portfolio').length > 0 || jQuery('ul#mycarousel').length > 0){
		if(jQuery('ul.portfolio').length > 0) var elem = jQuery('ul.portfolio li');
		else var elem = jQuery('ul#mycarousel li');
		//hover copertine progetti
		elem.hover(
			function(){
				//jQuery(this).animate({ borderColor: '#dedede' }, 700); //Effetto Bordo
				jQuery(this).find('img').stop().animate({ opacity: 0.2 }, 700);
				if(jQuery('table.summary').length == 0)
					mostraSommario(jQuery(this).find('img'));
			},
			function(){
				jQuery(this).find('table.summary').remove();
				jQuery(this).animate({ opacity: 1 }, 500);
				//jQuery(this).animate({ borderColor: '#404040' }, 700); //Effetto Bordo
				jQuery(this).find('img').stop().animate({ opacity: 1 }, 700);
			}
		);
		
		//Mostra titolo e descrizione Progetto
		function mostraSommario(ogg){
			var aLink = ogg.parent();
			
			var categoria = aLink.attr('rel');
			var titolo = aLink.attr('title');
			var descrizione = aLink.attr('lang').substring(0, 80);
			if(aLink.attr('lang').length > 80) descrizione += '...';
			
			ogg.parent().parent().append('<table class="summary"><tr><td><h2>' + categoria + '</h2><h1>' + titolo + '</h1><p>' + descrizione + '</p></td></tr></table>');
			var divSummary = ogg.parent().parent().find('table');
			divSummary.css({
				opacity: 0
			});
			divSummary.click(function(){
				document.location.href = aLink.attr('href');
			});
			divSummary.stop().animate({ opacity: 1 }, 1000);
		}
	}
	//Hover Portfolio se siamo dentro una categoria
	if(jQuery('ul.menu_portfolio').length > 0)
		jQuery('li.page-item-5').addClass('current_page_item');
		
	//Link immagini in HomePage
	if(jQuery('div.entry-index img').length > 0)
		jQuery.each(jQuery('div.entry-index img'),function(){
			jQuery(this).css('cursor', 'pointer');										
			jQuery(this).click(function(){
				document.location.href = jQuery(this).parent().parent().prev().find('a').attr('href');
			});
		});
		
});
//Jcarousel
function startJcarousel(nstart){
	jQuery(document).ready(function(){
		if(isNaN(nstart))nstart = 0;
		if(jQuery('#mycarousel').length > 0)jQuery('#mycarousel').jcarousel({  animation:'fast', start: nstart });
	});
}
