// JavaScript
// By Arūnas Paškevicius
$(document).ready(function(){
	$(".gallery-pics a").lightBox();
});

var domain = document.domain;

// Laikrodis 
function clock(target){	
	var obj = document.getElementById(target);
	var months_lt = new Array(
		'Sausio',
		'Vasario',
		'Kovo',
		'Balandžio',
		'Gegužės',
		'Birželio',
		'Liepos',
		'Rugpjūčio',
		'Rugsėjo',
		'Spalio',
		'Lapkričio',
		'Gruodžio'
	);
	var date = new Date();
	var printDate = date.getFullYear() + ' m. ' 
				  + months_lt[date.getMonth()] + ' '
				  + date.getDate() + ' d. ';
	if(date.getHours() < 10){
		printDate += '0' + date.getHours() + ':';
	}else{
		printDate += date.getHours() + ':';	
	}
	
	if(date.getMinutes() < 10){
		printDate += '0' + date.getMinutes();
	}else{
		printDate += date.getMinutes();	
	}		

	obj.innerHTML = printDate;	
	setTimeout("clock('"+target+"')", 30000);
}

function dropDown(target){
//	var obj = document.getElementById(target);
		$("#"+target).slideToggle("slow");
		
	/*
		if(obj.style.display == 'block'){
			obj.style.display = 'none';
		}else{
			obj.style.display = 'block';	
		}
		*/
}

// EVENTAI
var openedEventId = null;
var animated = false;

function closeEvent(){
	if(!animated){
		openedEventId = null;
		animated = true;
 	  $('#event_close').fadeOut('slow',function(){
			$('#event_frame').fadeOut('slow',function(){
				$(this).innerHtml = "";
				$(this).src = "about:blank";
				$(this).remove();																							
				$('#event_dialog').slideUp('slow',function() {
					$('#content').slideDown('slow',function(){
						animated = false;																								
					});
				});
			});	
  	});
	}
}

function openEvent(url,id){	
	if(!animated){
		animated = true;
		openedEventId = id;
		$('#content').slideUp("slow",function() {
			$('#event_dialog').slideDown('slow',function(){																										
				$('#event_dialog').append('<iframe id="event_frame" class="event_frame" frameborder="0" scrolling="no" src="' + url + '"></iframe>');
				$('#event_frame').css('display','none').load(function(){
				 $(this).fadeIn('slow',function(){ 	
					 $('#event_close').fadeIn('slow',function(){																				
				     animated = false;													
					 });
				 });
				});
			});
		}); 	 
	}
}

function changeEvent(url,id){	

	if(!animated){
		openedEventId = id;
		animated = true;
		$('#event_close').fadeOut('slow',function(){
			$('#event_frame').fadeOut("slow",function(){
				$(this).remove();
				$('#event_dialog').append('<iframe id="event_frame" class="event_frame" frameborder="0" scrolling="no" src="' + url + '"></iframe>');
				$('#event_frame').css('display','none').load(function(){																  
				 $(this).fadeIn('slow',function(){
					$('#event_close').fadeIn('slow',function(){																				
				     animated = false;													
					 });																			
				 });
				});
			});
	  });
 	}
}

function showEvent(button,url,id){
	var event_url = url;
	var event_button = button;
	
	if(!animated){
		if($('#event_dialog').css("display") == 'none'){
			$(event_button).attr("id","event_on");
			openEvent(event_url,id);
		}else{
			if($(event_button).is("#event_on")){
				closeEvent();
				$(event_button).removeAttr("id");
			}else{
				$("#event_on").removeAttr("id");
				$(event_button).attr("id","event_on");			
				changeEvent(event_url,id);				
			}
		}
	}
}
// AJAXui skirta 
var xmlHttp;

function contrCalendar(str)
{	
	if($$("event_frame")){
		str += ("&selected_event=" + openedEventId);
	}
	if (str.length==0)
	{ 
		document.getElementById("calendar").innerHTML="";
		return;
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url=str;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	document.getElementById("calendar").innerHTML=xmlHttp.responseText;	} 
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
		{	// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
	catch (e)
		{	// Internet Explorer
			try
				{	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");	}
		catch (e)
			{	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	}
		}
	return xmlHttp;
}