 var selected=0;
 var t;
 var t2;
 function startTime()
 {
 var today=new Date();
 var h=today.getHours();
 var m=today.getMinutes();
 var s=today.getSeconds();
 // add a zero in front of numbers<10
 h=checkTime(h);
 m=checkTime(m);
 s=checkTime(s);
 document.getElementById('clockDiv').innerHTML=h+":"+m;
 t=setTimeout('startTime()',500);
 }

 function checkTime(i)
 {
 if (i<10)
   {
   i="0" + i;
   }
 return i;
 }
 
 
 function changeHotNewsPrev(){
	 if (hotNew==0){
		 hotNew=hotNewsCount-1;
	 }else{
		 hotNew=hotNew-1;
	 }
	 $.get('ajax_content.php',{ new_no: hotNew, action: "getHotNew" }, function(data) {
		 $('#alpha_line_content').fadeOut('slow',function(){
			 $('#alpha_line_content').html(data).fadeIn('slow');
			 
		 });
		
		 t2=setTimeout('changeHotNews()',5000);
		 
		});
 }
 
 function changeHotNews(){
	 if ((hotNew+1)==hotNewsCount){
		 hotNew=0;
	 }else{
		 hotNew=hotNew+1;
	 }
	 $.get('ajax_content.php',{ new_no: hotNew, action: "getHotNew" }, function(data) {
		 $('#alpha_line_content').fadeOut('slow',function(){
			 $('#alpha_line_content').html(data).fadeIn('slow');
			 
		 });
		
		 t2=setTimeout('changeHotNews()',5000);
		  
		});
 }
 
 
 
 function hide(){
		if (selected==0){
			$('.idPop').fadeOut('fast');
			$(".pointer").hide();
		}
		//alert('hide');
	 }         
 function showPopMenu(categoryId){
	 //alert('ok'+currentId);
	 
	 if (selected==1){
		// alert("Hello world!");
    	 //var currentId = "#"+$(this).attr('id');
    	// setTimeout('showPopMenu("'+currentId+'");',500);
		 var currentId="#"+categoryId;
    	 var p = $(currentId);
    	 var position = p.position();
    	 
    	 //$(".idPop").css('top', position.top+($(this).outerHeight()));   
    	 //var currentId = "#"+$(this).attr('id');
    	 
    	 $.get('ajax_content.php',{ category_id: categoryId, action: "getMenuContent" }, function(data) {
    		  $('#res').html(data);
    		  $('.idPop').fadeIn('slow',function(){
    	    		 $(".pointer").css('marginLeft', (position.left+(($(currentId).outerWidth()/2))-11)).show(); 
    	    		 
    	    		 
    	    	 });
    	    	 
    	    	 
    	    	 $(".idPop").css('left', 0); 
    		});

		// $(".idPop").html("left: " + position.left + ", top: " + position.top +", "+currentId);
    	// $("p:last").text( "left: " + position.left + ", top: " + position.top +", "+currentId);
    	  	// selected=1;
		 
		 
		 
	 }
	 
	 
 }
 $(document).ready(function() {
	   t2=setTimeout('changeHotNews()',5000);
	   
	   $('#textCon').fontResizer({minFont:12,maxFont:18,increment:1});
	   
	   $("#poll_wote").click(function(event){
		   event.preventDefault();
		   value = $("input[@name=poll_answer_id]:checked").val();
		  if (value==null){
			  //alert('Nera');
		  }else{

		    	 $.get('ajax_content.php',{ poll_answer_id: value, poll_id:$("#poll_id").val(), action: "pollVote" }, function(data) {
		    		 //alert(data);
		    		 $('#fp_dienos_kls_cont').html(data);
		    		  //$('#res').html(data);
		    		 // $('.idPop').fadeIn('slow',function(){
		    	    	//	 $(".pointer").css('marginLeft', (position.left+(($(currentId).outerWidth()/2))-11)).show(); 
		    	    		 
		    	    		 
		    	    	// });
		    	    	 
		    	    	 
		    	    	// $(".idPop").css('left', 0); 
		    		});
			 // alert(value);
		  }
		   //alert(value);
		  // clearTimeout(t2);
		  // changeHotNews();
		   
	   });
	   
	   $("#hotNewNext").click(function(event){
		   event.preventDefault();

		   clearTimeout(t2);
		   changeHotNews();
		   
	   });
	   $("#hotNewPrev").click(function(event){
		   event.preventDefault();

		   clearTimeout(t2);
		   changeHotNewsPrev();
		   
	   });
	 //  $("a").click(function() {
	 	startTime()
	     $(".select").mouseenter(function() {
	    	 var currentId = $(this).attr('id');
	    	 t=setTimeout('showPopMenu("'+currentId+'");',500);
	    	 selected=1;
	     }).mouseleave(function() {
	    	 clearTimeout(t);
	    	 selected=0;
	    	 //onClick="setTimeout('',1000);";
	    	 setTimeout("hide()",1000);
	    	 
	     });
	     $('.idPop').mouseenter(function() {
	    	 selected=1;
	     }).mouseleave(function() {
	    	 selected=0;
	    	 setTimeout("hide()",1000);
	     });
	     
	     
	     $('#bottom_line').meerkat({
	    	    background: 'none',
	    	    height: '27px',
	    	    width: '1100px',
	    	    position: 'bottom',
	    	    close: '.close-meerkat',
	    	    dontShowAgain: '.dont-show',
	    	    animationIn: 'slide',
	    	    animationSpeed: 500,
	    	    delay: 1
	    	});
	 //  });
	     
	     
	     
	     
	     
	     
	     
	     
	     
	     
	     
	     $('a.yesno').click( function() {
	 		var confirmLink = $(this).attr("href");
	 		$('#dialog').dialog( {
	 			modal :true,
	 			autoOpen :false,
	 			width :450,
	 			title :$(this).children(".dialogMessage").attr("title"),
	 			close : function(event, ui) {
	 				$(this).dialog('destroy');
	 			},
	 			buttons : {
	 				"Ne" : function() {
	 					$(this).dialog("close").dialog('destroy');
	 					},
	 				"Taip" : function() {
	 					window.location = confirmLink;
	 					$(this).dialog("close").dialog('destroy');
	 					}
	 			}
	 		});
	 		$('#dialog').html($(this).children(".dialogMessage").html());
	 		$('#dialog').dialog('open');
	 		return false;
	 	});

	 	$('a.dialog').click(
	 			function() {
	 				$('#dialog').load(
	 						$(this).attr("href"),
	 						{ 

	 						},
	 						function() {
	 							var buttons = {};
	 							var submit = $(this).children("div").children(
	 							"form").find('input[type=submit]');
	 							if (submit.val() != null) {
	 								submit.css("display", "none");
	 								buttons[submit.val()] = function() {
	 									$(this).children("div").children("form")
	 									.submit();
	 								};

	 							} else {

	 							}
	 							$('#dialog').dialog( {
	 								modal :true,
	 								autoOpen :false,
	 								width :490,
	 								buttons :buttons,
	 								open : function (event, ui) {
	 									init_js();
	 								},
	 								close : function(event, ui) {
	 									
	 									
	 									
	 									$(this).dialog('destroy');
	 								},

	 							title :$(this).children("div").attr("title")

	 							});
	 							$('#dialog').dialog('open');

	 						});
	 				return false;
	 			});
	     
	     
	     
	     
	     
	     
	 });   
