// JavaScript Document

// Username & Password Clear

function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
if (thisfield.name == "psw") {
thisfield.type = "password";
}
}
}

function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
thisfield.type = "text";
}
}


function initMenu() {

$('#accordion .text').hide();
if(!$('#accordion').is('.closable')) {
	$('#accordion .header:first').addClass('opened');
	$('#accordion .text:first').show();
	$('#accordion .news_date:first').css({backgroundPosition : '0px -52px'});
}

$('#accordion .header').click( function() {
		$(this).find('.programma_color').addClass('white');
		var checkElement = $(this).next();
		if((checkElement.is('.text')) && (checkElement.is(':visible'))) {
		$(this).addClass('opened');
			if($('#accordion').is('.closable')) {
				$('#accordion .text:visible').slideUp('slow');
				$('.header').each(function() { $(this).removeClass('opened').find('.programma_color').removeClass('white')});
			}
			return false;
		}
		if((checkElement.is('.text')) && (!checkElement.is(':visible'))) {
			$('.header').each(function() { $(this).removeClass('opened').find('.programma_color').removeClass('white')});
			$('#accordion .text:visible').slideUp('slow');
			$('#accordion .news_date').css({backgroundPosition : '0px 0px'});
			$(this).children('.news_date').css({backgroundPosition : '0px -52px'});
			$(this).addClass('opened').find('.programma_color').addClass('white');
			checkElement.slideDown('slow');
			return false;
	}
	});
}

// Social Network


SN_left = (screen.width/2)-(650/2);
SN_top = (screen.height/2)-(450/2);


function socialShareFB(shareTitle, shareImg, shareDesc) {
	window.open("http://www.facebook.com/sharer.php?s=100&p[title]=" + shareTitle + " all'Estragon&p[url]=http://www.estragon.it/programma.php&p[images][0]=http://www.estragon.it/estragon2010/programma/"+ shareImg + "&p[summary]=" + shareDesc, "Condividi Evento su Facebook", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=650, height=450, left=" + SN_left + ", top=" + SN_top);
};

function socialShareTW(tw_text) {
	window.open("https://twitter.com/share?url=http://www.estragon.it/programma.php&text=" + tw_text + "&lang=it&related=estragonclub", "Condividi Evento su Twitter", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=650, height=450, left=" + SN_left + ", top=" + SN_top);
};

function socialNewsFB(newsTitle, newsDesc) {
	window.open("http://www.facebook.com/sharer.php?s=100&p[title]=" + newsTitle + "&p[url]=http://www.estragon.it/&p[images][0]=http://www.estragon.it/estragon2010/_home/news_social.jpg&p[summary]=" + newsDesc, "Condividi News su Facebook", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=650, height=450, left=" + SN_left + ", top=" + SN_top);
};

function socialNewsTW(tw_news) {
	window.open("https://twitter.com/share?url=http://www.estragon.it&text=" + tw_news + "&lang=it&related=estragonclub", "Condividi News su Twitter", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=650, height=450, left=" + SN_left + ", top=" + SN_top);
};

// AJAX

$(document).ready(function() {

$('#tweets').tweetable({username: 'estragonclub', time: true, limit: 1, replies: false, position: 'append'});

initMenu();

$('.img_consiglia').tipsy({gravity: 'e', html: true, offset: 10});
$('.sh_butt').tipsy({gravity: 's', offset: 4, live: true});

// Ingrandimento Immagini

$("a.fancy").fancybox({
	'zoomSpeedIn': 1000,
	'zoomSpeedOut': 300,
	'overlayShow': true,
 	'hideOnContentClick': false, 
	'easingIn' : 'easeOutBack',
	'easingOut' : 'easeInBack',
	'imageScale' : true
});

// Controller
	$(".programma_prezzo:contains(','), .programma_prezzo:contains('.')").css({'font-size' : '12px'});

// MENU Animation

$('.menu_button.left').mouseover(function(){
		$(this).next().css({backgroundPosition: '0px -14px'});
}).mouseout(function(){
		$(this).next().css({backgroundPosition: '0px 0px'});
});

$('.menu_button.right').mouseover(function(){
		$(this).prev().css({backgroundPosition: '0px -28px'});
}).mouseout(function(){
		$(this).prev().css({backgroundPosition: '0px 0px'});
});
	
$('.menu_button').mouseover(function(){
		$('.menu_button').not($(this)).stop().animate({opacity: 0.5}, 300);	
		$(this).stop().animate({opacity: 1}, 200);	
}).mouseout(function(){
		$('.menu_button').stop().animate({opacity: 1}, 800);
});

$('.header').mouseover(function(){
		$(this).find('.programma_color').addClass('white');
		if(!$(this).hasClass('opened')) {
			$(this).find('.leggi').html('leggi tutto');
		};
}).mouseout(function(){
		$(this).find('.leggi').html('');
		if(!$(this).hasClass('opened')) {
			$(this).find('.programma_color').removeClass('white');
		};
});

$('#rss').stop().animate({opacity : 0.6}, 2000);
$('#rss').mouseover(function(){
		$(this).stop().animate({marginTop : '-=3px', opacity : 1, backgroundPosition : '0px -27px'}, 'fast');
}).mouseout(function(){
		$(this).stop().animate({backgroundPosition : '0px 0px', marginTop : '+=3px', opacity : 0.6}, 'fast');
});

// Riflessione Immagine

$(function() {
			$('img.reflect_oggi').reflect({height: 0.5, opacity: 0.3} );
			$('img.reflect_estragon').reflect({height: 0.4, opacity: 0.3} );
			$('img.reflect_logo').reflect({height: 0.4, opacity: 0.5} );
});

// Banner

$(function() {
$('.banner').cycle({ 
    fx:    'fade', 
    speed:  700,
	timeout: 8000,
    delay:  -2000

 });
});

$(function() {
$('#video').cycle({ 
    fx:    'fade', 
    speed:  2000,
	timeout: 6000,
    delay:  1000

 });
});

$(function() {
$('#dove_pic').cycle({ 
    fx:    'scrollDown', 
    speed:  1000,
	timeout: 5000,
    delay:  -2000

 });
});
// Links LINKS

$('#link_box li').mouseover(function(){
		$(this).stop().animate({backgroundPosition : '5px -11px', paddingLeft : '20px'}, 300);
});
	$('#link_box li').mouseout(function(){
		$(this).stop().animate({backgroundPosition : '0px 0px', paddingLeft : '10px'}, 300);
});

// Link IMMAGINI

$('.img_links').stop().animate({opacity : 0.5}, 100);
$('.img_links').mouseover(function(){ $(this).stop().animate({opacity : 1}, 500); }).mouseout(function(){ $(this).stop().animate({opacity : 0.5}, 500); });
$('.banner, .social').mouseover(function(){ $(this).stop().animate({opacity : 0.5}, 500); }).mouseout(function(){ $(this).stop().animate({opacity : 1}, 500); });
	
// Foto Mese

$('.img_over').css({opacity : 0});
$('.img_over').mouseover(function(){ $(this).stop().animate({opacity : 1}, 200); });
$('.img_over').mouseout(function(){ $(this).stop().animate({opacity : 0}, 200); });

$('.foto_mese').children('img').stop().css({height : '170px', width : '210px', marginTop : '-15px', marginLeft : '-15px'});
$('.foto_mese').mouseover(function(){
		$(this).children('img').stop().animate({height : '140px', width : '180px', marginTop : '0px', marginLeft : '0px'}, 300);
}).mouseout(function(){
		$(this).children('img').stop().animate({height : '170px', width : '210px', marginTop : '-15px', marginLeft : '-15px'}, 300);
});

// Immagini

$('.img_dett').children('a').children('img').css({height : '170px', width : '210px', marginTop : '-15px', marginLeft : '-15px'});

$('.img_dett').mouseover(function(){
		$(this).children('a').children('img').stop().animate({height : '140px', width : '180px', marginTop : '0px', marginLeft : '0px'}, 300);
});
	$('.img_dett').mouseout(function(){
		$(this).children('a').children('img').stop().animate({height : '170px', width : '210px', marginTop : '-15px', marginLeft : '-15px'}, 300);
});

// Cerca

$('.lens').mouseover(function(){ $(this).stop().css({opacity : 0.5}); }).mouseout(function(){ $(this).stop().css({opacity : 1}); });


});
