// JavaScript Document
/**
  Theme Name: YDL
  Author: WebFandom
  Author URI: http://www.webfandom.com
*/

jQuery(document).ready(function(){
	
	/*Scroll delle voci del footer*/
	jQuery('#footer .alignright a').click(function() {
  		var targetOffset = jQuery('#top').offset().top;
   		jQuery('html,body').animate({scrollTop: targetOffset}, 1000);
       return false;
	});
	
	/* Slide */
	jQuery('#loopedSlider').loopedSlider({
		autoStart: 4000, 
        slidespeed: 300
	});
	
	/* Funzioni che spostano alcuni elementi dello slidebox */
	jQuery('#slide .more-link').slide_more();
	
	/*Setta lo stile diverso per eventi nella sidebar*/
	jQuery('#side_content h2').eventi();
	
	/* Hover delle immagini flickr */
	jQuery('.flickr li').hover(function(){
		jQuery(this).css('background','#f8fa3c');
	},function(){
		jQuery(this).css('background','#c2c2c2');
	});
	
	jQuery('#main .more,#main .commenti').hover(function(){
		jQuery(this).css('text-decoration','underline');
	},function(){
		jQuery(this).css('text-decoration','none');
	});
	
	jQuery('#main a img').parent().css('padding','5px');

		var popup = false;
	
	jQuery('.ydl_form_content,.ydl_form_content2').click(function()
	{
		popup = true;
	});
	
	jQuery('.ydl_form').click(function()
	{
		if( !popup)
		{
			jQuery(this).css('display','none');
			jQuery('.ydl_form_content').css('display','none');
			jQuery('.ydl_form_content2').css('display','none');
			jQuery('.ydl_form_content3').css('display','none');
			jQuery('.ydl_form_content3 .video').html('');
		}
		popup = false;
	});
	
	jQuery('.close_pup').click(function()
	{
		jQuery('.ydl_form').css('display','none');
		jQuery('.ydl_form_content').css('display','none');
		jQuery('.ydl_form_content2').css('display','none');
		jQuery('.ydl_form_content3').css('display','none');
		jQuery('.ydl_form_content3 .video').html('');
		popup = false;
	});
	
	jQuery('.apri_ydl_popup').click(function(){
		jQuery('.ydl_form').show();
		jQuery('.ydl_form_content').show('fast');
	});
	
	jQuery('.headContact').click(function(){
		jQuery('.ydl_form').show();
		jQuery('.ydl_form_content2').show('fast');
	});
	
	jQuery('.formVideoOpen').click(function(){
		jQuery('.ydl_form').show();
		jQuery('.ydl_form_content3').show('fast');
		jQuery('.ydl_form_content3 .video').html('<iframe title="YouTube video player" class="youtube-player" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/9Wsz2Mjkt7I?hd=1&amp;autoplay=1" style="margin-top:7px" frameborder="0" allowfullscreen></iframe>');
	});

});

/* Funzioni che spostano alcuni elementi dello slidebox */

jQuery.fn.slide_more = function() {
    for(i = 0; i < jQuery(this).size() ;i++)
	{
		jQuery(this[i]).appendTo(jQuery(this[i]).parent().parent().parent().children('.meta'));
	}
};

jQuery.fn.eventi = function() {
    for(i = 0; i < jQuery(this).size() ;i++)
	{
		if(jQuery(this[i]).text() == 'EVENTI')
		{
			jQuery(this[i]).attr('class','eventi');
			jQuery(this[i]).css('background','#f8fa3c');
		}
	}
};
