var film_count = 0;
var film_width = 120;
var left_timer ;
var right_timer ;
var sponsor_counter = 0;

var timeOutTable = new Array;

var sel_name_menu = "dlga"

function main()
	{
	var film_kids = $("div#content_left_bottom_film_carousel_films").children();
	film_count = film_kids.length;

	$("div#film_carousel_left").click(function(event){move_left(500,film_count);});
	$("div#film_carousel_right").click(function(event){move_right(500,film_count);});

	pic1= new Image(); 
	pic1.src="/_img/_menu/_dlga_scrool_menu.jpg"; 
	pic1= new Image(); 
	pic1.src="/_img/_menu/_dlga_scrool_menu_hover.jpg"; 


	$("#form00").submit(function() {
		var t = true;

		$("img#img_name_surname").fadeOut("fast")
		if($("input[name='name_surname']").val() == "")
			{
			$("img#img_name_surname").fadeIn("fast")
			t = false
			}

		$("img#img_hcp").fadeOut("fast")
		if($("input[name='hcp']").val() == "")
			{
			$("img#img_hcp").fadeIn("fast")
			t = false
			}

		$("img#img_count").fadeOut("fast")
		if($("input[name='count']").val() == "")
			{
			$("img#img_count").fadeIn("fast")
			t = false
			}

		$("img#img_pole").fadeOut("fast")
		if($("input[name='pole']").val() == "")
			{
			$("img#img_pole").fadeIn("fast")
			t = false
			}

		$("img#img_tel").fadeOut("fast")
		if($("input[name='tel']").val() == "")
			{
			$("img#img_tel").fadeIn("fast")
			t = false
			}

		$("img#img_mail").fadeOut("fast")
		if($("input[name='mail']").val() == "")
			{
			$("img#img_mail").fadeIn("fast")
			t = false
			}

		return t;
		});

	$("div.menu_bookmarks_bottom_elem").mouseenter(function(event){
			id = $(this).attr("rel");
			$("div#menu_bookmarks_bottom_"+sel_name_menu+"_elem_div_"+id).css("background-image", "url(/_img/_menu/m_"+sel_name_menu+"_left_hover.gif)");
			$("a#menu_bookmarks_bottom_"+sel_name_menu+"_elem_a_"+id).css("background-image", "url(/_img/_menu/m_"+sel_name_menu+"_right_hover.gif)");
		});

	$("div.menu_bookmarks_bottom_elem").mouseleave(function(event){
			id = $(this).attr("rel");
			$("div#menu_bookmarks_bottom_"+sel_name_menu+"_elem_div_"+id).css("background-image", "url(/_img/_menu/m_"+sel_name_menu+"_left.gif)");
			$("a#menu_bookmarks_bottom_"+sel_name_menu+"_elem_a_"+id).css("background-image", "url(/_img/_menu/m_"+sel_name_menu+"_right.gif)");
			hideAllSubMenu();
		});

	$("div.scrool_menu div").mouseenter(function(event){
		id = $(this).attr("rel");
		$("div.scrool_menu_"+sel_name_menu+"_"+id+"_c").css("background-image", "url(/_img/_menu/_"+sel_name_menu+"_scrool_menu_hover.jpg)");
		});

	$("div.scrool_menu div").mouseleave(function(event){
		id = $(this).attr("rel");
		$("div.scrool_menu_"+sel_name_menu+"_"+id+"_c").css("background-image", "url(/_img/_menu/_"+sel_name_menu+"_scrool_menu.jpg)");
		});

	$("div.menu_bookmarks_bottom_elem").mouseenter(function(event){
		id = $(this).attr("rel");
		hideAll(id)
		$("div#scrool_menu_"+sel_name_menu+"_" + id).fadeIn("fast");
		});

	$("div.menu_bookmarks_bottom_elem").mouseleave(function() {
		id = $(this).attr("rel");
		});


	$("div#menu_bookmarks_top_left a").mouseenter(function() {
 		i = $(this).attr("rel"); 		
		//change_tabs(i);	
	});
	
	$('.cover').click(function() {
		id = $(this).attr('rel');		
		$.ajax({
			url: "/show_advice.php",
			data: "id=" + id,		
			cache: false,
			success: function(html){
				$('#youtube_player_container').html(html);
			}
		}); 	
		
	});
	
	$('#btn_newsletter_address').click(function() {
		mail = $('#newsletter_address').val();
		if (mail.length == 0 || mail == 'e-mail') {
			alert("Proszę podać adres e-mail.");
		} else {		
			$('#newsletter_address').val('Proszę czekać');
			$.ajax({
				async: false,
				url: "/ajax_add_mail_to_newsletter.php",
				data: "mail=" + mail,		
				cache: false,
				success: function(html){
					$('#newsletter_address').val('');
					alert('Twój adres został dodany');
				}
			});			
		}
	});
	
	show_sponsor();
	
}

function next_short_news() {
	max = $('#short_news_number').attr('rel');
	max = Number(max);	
	
	if (max != 0) {			
		ile = $('#short_news_box').attr('rel');	
		ile = Number(ile);
		
		if (ile < max) {
			next_ile = ile + 1;
		} else {
			next_ile = 1;
		}
			
		$('#short_news_box').html('');
		$.ajax({
			url: "/get_short_news.php",
			data: "ile=" + next_ile,		
			cache: false,
			success: function(html){
				$('#short_news_box').attr('rel', next_ile);
				$('#short_news_box').html(html);
			}
		});
	} 	
}

function prev_short_news() {
	max = $('#short_news_number').attr('rel');
	max = Number(max);
	
	if (max != 0) {		
		ile = $('#short_news_box').attr('rel');
		ile = Number(ile);
		
		if (ile > 1) {
			next_ile = ile - 1;
		} else {
			next_ile = max;
		}
		$('#short_news_box').html('');
		$.ajax({
			url: "/get_short_news.php",
			data: "ile=" + next_ile,		
			cache: false,
			success: function(html){
				$('#short_news_box').attr('rel', next_ile);
				$('#short_news_box').html(html);
			}
		});
	} 	
}

function show_sponsor() {
	all = $('#sponsor_animation').attr('rel');
	all = Number(all);
	if (all != 0) {				
		$('img.sponsor_image_' + sponsor_counter).show();
		setTimeout("hide_sponsor();", 2000);				
	}
}

function hide_sponsor() {
	all = $('#sponsor_animation').attr('rel');
	all = Number(all);
	if (all != 0) {				
		$('img.sponsor_image_' + sponsor_counter).hide();
		if (sponsor_counter < (all-1)) { 
			sponsor_counter++;
		} else {
			sponsor_counter = 0;
		}
		show_sponsor();
	}
}

function change_tabs(i) {
	if (i != 2 && i >=0 && i <= 3) {
 		$("div#menu_bookmarks").css({backgroundPosition: "0px -"+(i * 97)+"px"})

		$("div#menu_bookmarks_bottom_dlga").css("display","none");
		$("div#menu_bookmarks_bottom_pole").css("display","none");
		$("div#menu_bookmarks_bottom_klub").css("display","none");
		$("div#menu_bookmarks_bottom_rest").css("display","none");
		if(i == 0)
			{
			$("div#menu_bookmarks_bottom_dlga").css("display","block");
			sel_name_menu = "dlga";
			hideAllSubMenu();
			}
		else if(i == 1)
			{
			$("div#menu_bookmarks_bottom_pole").css("display","block");
			sel_name_menu = "pole";
			hideAllSubMenu();
			}
		else if(i == 2)
			{
			$("div#menu_bookmarks_bottom_klub").css("display","block");
			sel_name_menu = "klub";
			hideAllSubMenu();
			}
		else if(i == 3)
			{
			$("div#menu_bookmarks_bottom_rest").css("display","block");
			sel_name_menu = "rest";
			hideAllSubMenu();
			}
	}
}

function move_left(speed,film_count)
	{
	if(parseInt( $("div.film_prev.0").css("left") ) < 0)
		{
		$("div#content_left_bottom_film_carousel_films").children().animate({"left": "+="+film_width+"px"}, speed/5 ,function(){

			});
		}
	else
		{
		$("div#content_left_bottom_film_carousel_films").children().stop();
		}
	}

function move_right(speed,film_count)
	{
	if( parseInt( $("div.film_prev."+(film_count - 1)).css("left") + film_width )  >= 540 - film_width )
		{
		$("div#content_left_bottom_film_carousel_films").children().animate({"left": "-="+film_width+"px"}, speed/5,function(){
			});
		}
	else
		{
		$("div#content_left_bottom_film_carousel_films").children().stop();
		}
	}

function hideAll(id)
	{
	for (var i = 0; i < 7; ++i)
		{
		if (i != id)
			{
			hideSubMenu(i);
			}
		}
	}

function hideSubMenu(id)
	{
	$("div#scrool_menu_"+sel_name_menu+"_" + id).css("display","none")
	}

function hideAllSubMenu()
	{
	$("div.scrool_menu").css("display","none")
	}

function startHiding(id)
	{
	timeOutTable[id] = setTimeout('hideSubMenu(\'' + id +'\')', 100)
	}
function stopHiding(id)
	{
	clearTimeout(timeOutTable[id]);
	}
	
function displayWindow(url, width, height) {
	var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=0,menubar=no' );
}
