var menu = null;
var mc_custom_error_style = '';

function checkHover() {
	if ( menu ) {
		menu.find ( 'ul' ).fadeOut ( 'fast' );	
	} //if
} //checkHover

$ ( document ).ready ( function () {

	// Υλοποιήση Popup Menu
	$ ( '.menu > li' ).hover ( function () {

		if ( menu ) {
			menu.find ( 'ul' ).fadeOut ( 'fast' );
			menu = null;
		} //if
		
		$ ( this ).find ( 'ul' ).fadeIn ( 'fast' );
	}, function() {
		menu = $ ( this );
		setTimeout ( "checkHover()", 400 );
	});

	// Υλοποίηση Slider
	function formatText ( index, panel ) {
		return index + "";
	} // end function

	$ ( function () {

		$ ( '.anythingSlider' ).anythingSlider ({
        	easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 4000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 1000,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "",                // Start text
			stopText: "",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});

		$ ( '.insideSlider' ).anythingSlider ({
        	easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 4000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 1000,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "",                // Start text
			stopText: "",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});

		$ ( '.insideSlider2' ).anythingSlider ({
        	easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 4000,                    // How long between slide transitions in AutoPlay mode
			startStopped: true,            // If autoPlay is on, this can force it to start stopped
			animationTime: 1000,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "",                // Start text
			stopText: "",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});
	}); // end slider

	addCalendar ( "Calendar0", "Select Date", "start_date", "agenda_form" );
	addCalendar ( "Calendar1", "Select Date", "end_date", "agenda_form" );
	setMonthNames("Ιανουάριος", "Φερουάριος", "Μάρτιος", "Απρίλιος", "Μάιος", "Ιούνιος", "Ιούλιος", "Αυγουστος", "Σεπτέμβριος", "Οκτώβριος", "Νοέμβριος", "Δεκέμβριος");
	setDayNames ( "Κυριακή", "Δευτέρα", "Τρίτη", "Τετάρτη", "Πέμπτη", "Παρασκευή", "Σαββάτο" );
	setLinkNames ( "Κλείσιμο&nbsp;", "&nbsp;Καθάρισμα" );

	$ ( "#mc-embedded-subscribe-form" ).submit ( function () {
		$ ( ".newsletter_message" ).html ( 'Ευχαριστούμε για την εγγραφή σας' );
	});

	$ ( '#search_button' ).click ( function () {
		$ ( '#search_form' ).submit ();
	});

	$ ( '#search_textfield' ).focus ( function () {
		$ ( this ).val ( '' );
	});

	$ ( '#video_search' ).focus ( function () {
		$ ( this ).val ( '' );
	});

	$ ( '#video_go' ).click ( function () {
		$ ( '#fm_search_video' ).submit ();
	});


	// Click σε Links και Διευθύνσεις
	$ ( 'a#view_links' ).click ( function () {
		$ ( 'div.links2' ).fadeOut ( 'fast' );
		$ ( 'div.links1' ).fadeIn ( 'fast' );
	});

	$ ( 'a#view_addresses' ).click ( function () {
		$ ( 'div.links1' ).fadeOut ( 'fast' );
		$ ( 'div.links2' ).fadeIn ( 'slow' );
	});


	// Κλικ στα Δημοφιλή
	$ ( 'a#btn_popular1' ).click ( function () {
		$ ( 'div#popular2' ).fadeOut ( 'fast', function () {
			//$ ( 'div#popular3' ).fadeOut ( 'fast', function () {
				$ ( 'div#popular1' ).fadeIn ( 'fast' );
			//});
		});		
	});

	$ ( 'a#btn_popular2' ).click ( function () {
		$ ( 'div#popular1' ).fadeOut ( 'fast', function () {
			//$ ( 'div#popular3' ).fadeOut ( 'fast', function () {
				$ ( 'div#popular2' ).fadeIn ( 'fast' );
			//});
		});		
	});

	$ ( 'a#btn_popular3' ).click ( function () {
		$ ( 'div#popular1' ).fadeOut ( 'fast', function () {
			$ ( 'div#popular2' ).fadeOut ( 'fast', function () {
				$ ( 'div#popular3' ).fadeIn ( 'fast' );
			});
		});		
	});

	// Κλικ σε κατηγορία video που έχει υποκατηγορίες
	$ ( 'li.show_videosub' ).click ( function () {
		obj = $ ( this ).find ( 'ul' );

		if ( obj. css ( 'display' ) == 'none' )
		{
			obj.show ( 'slow' );
		} // end if
		else
		{
			obj.hide ( 'slow' );
		} // end else
	});

	// Κάνοντας κλικ σε κύρια κατηγορία στην agenda
	/*
	$ ( '.subcat' ).click ( function () {

		var id = $ ( this ).attr ( 'id' );
		var temp = id.split ( '_' );
		var obj = $ ( '.sub_' + temp [ 1 ] );

		if ( obj.css ( 'display' ) == 'none' )
		{
			obj.slideDown ( 'slow' );
		} // end if
		else
		{
			obj.slideUp ( 'slow' );
		} // end else

		$ ( '.subcat_ul' ).each ( function () {
			$ ( this ).fadeOut ( 'fast' );
		});

	});
	*/

	$ ( '.subcat' ).click ( function () {

		var id = $ ( this ).attr ( 'id' );
		var temp = id.split ( '_' );
		var catid = 'subcat_ul_' + temp [ 1 ];

		$ ( '.subcat_ul' ).each ( function () {
			id = $ ( this ).attr ( 'id' );

			if ( id == catid )
			{
				$ ( this ).slideToggle ();
			} // end if
			else
			{
				$ ( this ).fadeOut ();
			} // end else
		});

	});

	enable_next_month ();
	enable_previous_month ();

	$ ( '#full_width' ).click ( function ( e ) {
		//window.open ( 'http://ad-emea.doubleclick.net/click;h=v2|3E2F|0|0|%2a|p;244285306;0-0;0;68038885;31-1|1;43357980|43375767|1;;%3fhttp://www.facebook.com/FischerBeerGreece', 'Fischer', '' );
		//e.stopPropagation();
		//alert ( 'eee' );
	});

	$ ( '.container_main' ).click ( function ( e ) {
		return false;
	});
});

function enable_next_month ()
{
	$ ( '#next_month_button' ).click ( function () {
		var month = $ ( '#next_month' ).val ();
		var year = $ ( '#next_year' ).val ();
		var cat = $ ( '#cat' ).val ();

		$ ( '#calendar_container' ).load ( 'calendar.php', { 'month': month, 'year': year, 'cat': cat }, function () {
			enable_next_month ();
			enable_previous_month ();
		});
	});
} // end function enable_next_month

function enable_previous_month ()
{
	$ ( '#previous_month_button' ).click ( function () {
		var month = $ ( '#previous_month' ).val ();
		var year = $ ( '#previous_year' ).val ();
		var cat = $ ( '#cat' ).val ();

		$ ( '#calendar_container' ).load ( 'calendar.php', { 'month': month, 'year': year, 'cat': cat }, function () {
			enable_next_month ();
			enable_previous_month ();
		});
	});
} // end function enable_previous_month

// JavaScript Document
function blank ( x )
{
	 var length = x.length;
	 var result = 1;

	for ( i = 1; i <= length; i++ )
	{
		if ( x.charAt(i-1) != " " ) {
			
			result = 0;
			break;
		}
	} 
	return result;
} // end function blank

function check_contact_form ( language )
{
	var firstname = document.getElementById ( 'firstname' ).value;
	var lastname = document.getElementById ( 'lastname' ).value;
	var tel = document.getElementById ( 'tel' ).value;
	var email = document.getElementById ( 'email' ).value;

	var msg = "Δεν έχετε συμπληρώσει τα παρακάτω πεδία\n";
		
	if ( blank ( firstname ) ) {
		msg = msg + "- Όνομα\n";
	}
		
	if ( blank ( lastname ) ) {
		msg = msg + "- Επώνυμο\n";
	}
		
	if ( blank ( email ) ) {
		msg = msg + "- E-mail";	
	}
	else if ( !email.match(/(\w+)@(.+)\.(\w+)$/) ) {
		msg = msg + "- Το e-mail δεν είναι έγκυρο";
	}
		
	if ( msg != "Δεν έχετε συμπληρώσει τα παρακάτω πεδία\n" ) {
		alert ( msg );
		return false;
	}
	
	document.getElementById ( 'contact_form' ).submit ();	
} // end function check_contact_form

function Change_Font_Size ( size )
{
	switch ( size )
	{
		default:
			txt = 'normal';
		break;

		case 2:
			txt = 'large';
		break;

		case 3:
			txt = 'largest';
		break;
	} // end switch

	document.getElementById ( 'left' ).className = txt;
} // end function Change_Font_Size

function openEmailToFriend ( url )
{
	var width = 300;
	var height = 400;
	window.open ('http://www.culturenow.gr/includes/email_url.php?id='+url,"_blank","top=200,left=200,width="+width+",height="+height+",menubar=0,scrollbars=0,status=0");	
} // end function openEmailToFriend
	
function openPrint ( url )
{
	var width = 630;
	var height = 480;
	window.open ('http://www.culturenow.gr/includes/printable.php?id='+url,"_blank","top=200,left=200,width="+width+",height="+height+",menubar=0,scrollbars=1,status=0");	
}
