function in_array(string, array)  
{  
	for (i = 0; i < array.length; i++)  
	{  
		if(array[i] == string)  
		{  
			return true;  
		}  
	}  
	return false;  
} 

jQuery.fn.klientai_fade = function(){
	var all_text = "<table style=\"width:100%;\" border=\"0\">";
	var elementai = Array();
	var z=0;
	for (var i=0; i<12; i++)
	{
		z++;
		for (var j=0; j<100; j++)
		{
			element = Math.floor(Math.random()*all_clients.length);
			if (!in_array(element, elementai)) { elementai[i] = element; break; }
		}

		if (z==1) all_text += "<tr>";
		all_text += "<td style=\"height:94px; _height:92px; .height:92px; text-align:center; vertical-align:middle; .vertical-align:middle; _vertical-align:top;\"><img src=\""+all_clients[element]+"\" title=\""+all_clients_title[element]+"\" alt=\""+all_clients_title[element]+"\" /></td>";
		
		if (z==2) { all_text += "</tr>"; z=0; }
	}

	all_text += "</table>";
	this.fadeOut("400");
	setTimeout( "$('#visi_logotipai').html('"+all_text+"')", 400);
	setTimeout( "$('#visi_logotipai').fadeIn(\"400\");", 400);
	setTimeout( "$('#visi_logotipai').klientai_fade()", 5000);
};

function google_map_initialize() {
	var latlng = new google.maps.LatLng(54.904004,23.959186);
	var myOptions = {
		zoom: 15,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var marker = new google.maps.Marker({
		position: latlng, 
		map: map,
		title:"Itesta"
	});   
}

$(document).ready(function(){
	$('#contacts input').attr('autocomplete','off');

	$('#logo,#darbu_grupes,#darbai_container,#menu_container').disableTextSelect();

	$(".tltip").tooltip({cssClass:"tooltip",delay:0, opacity:10, fadeDuration:200 });

	$('img.captify').captify({
		// all of these options are... optional
		// ---
		// speed of the mouseover effect
		speedOver: 'fast',
		// speed of the mouseout effect
		speedOut: 'fast',
		// how long to delay the hiding of the caption after mouseout (ms)
		hideDelay:30,
		// text/html to be placed at the beginning of every caption
		prefix: '',		
		// opacity of the caption on mouse over
		opacity: '0.5',					
		// the name of the CSS class to apply to the caption box
		className: 'caption-bottom',	
		// position of the caption (top or bottom)
		position: 'bottom',
		// caption span % of the image
		spanWidth: '100%'
	});
 
	if ( !$.cookie('li_pos') ) {
		var options = { path: '/', expires: 1 };
		$.cookie('li_pos', id2+'|'+0, options);
	}
	var cookie_li_pos = $.cookie('li_pos').split("|"); 
	var page = cookie_li_pos[0];
	var li_pos = 0;
	if (page==id2) {
		li_pos = parseInt(cookie_li_pos[1]);
	} else {
		var options = { path: '/', expires: 1 };
		$.cookie('li_pos', id2+'|'+0, options);
	}

	// --- darbai ------------------------------------------------------------------------------------------------------------------
	$('#arrow_left').hide();
	$('#arrow_right').hide();
	if ( $('#slideshow li').size()>4 && $('#slideshow li').size()-li_pos>=0 && $('#slideshow li').size()-li_pos<$('#slideshow li').size() ) $('#arrow_left').show();
	if ( $('#slideshow li').size()>4 && $('#slideshow li').size()-li_pos>4 ) $('#arrow_right').show();

	$('#slideshow').mousewheel(function(event, delta){ 
		var kryptis;
		if (delta > 0) {
			if ( $('#arrow_left').is(':visible') ) kryptis = 'prev';
		} else {
			if ( $('#arrow_right').is(':visible') ) kryptis = 'next';
		}
		if (kryptis) $(this).trigger( kryptis );
		return false;
	});

	$('#slideshow').serialScroll({
		items:'li',
		prev:'#arrow_left',
		next:'#arrow_right',
		start: li_pos, 
		duration:300,
		step:1,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		jump: false, //click on the images to scroll to them
		onBefore:function( e, elem, $pane, $items, pos ){
			var new_pos = id2+'|'+pos;
			var options = { path: '/', expires: 1 };
			$.cookie('li_pos', new_pos, options);

			var stulpeliu_kiekis = 4;
			if (Math.floor(($(window).width()-300)/210)>=4) stulpeliu_kiekis = Math.floor(($(window).width()-300)/210);

			if ( pos==0 ) {
				$('#arrow_left').hide();
			} else {
				$('#arrow_left').show();
			}
			if ( (pos+stulpeliu_kiekis)==$('#slideshow li').size() ) {
				$('#arrow_right').hide();
			} else {
				$('#arrow_right').show();
			}
			
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});

	if ( $('#'+$.cookie('darbas')).attr('id') ) {
		$('#'+$.cookie('darbas')).fadeTo("slow", 0.2);
		$('#'+$.cookie('darbas')).fadeTo("slow", 1);

		var options = { path: '/', expires: 1 };
		$.cookie('darbas', 'x', options);
	}

	$('.darbas_list_container').click(function(){
		var darbo_id = $(this).attr('id');
		var options = { path: '/', expires: 1 };
		$.cookie('darbas', darbo_id, options);
	});

	


	// --- klientai ------------------------------------------------------------------------------------------------------------------
	$('#arrow_left_small').hide();
	$('#arrow_right_small').hide();
	if ( $('#slideshow_clients li').size()>3 && $('#slideshow_clients li').size()-li_pos>=0 && $('#slideshow_clients li').size()-li_pos<$('#slideshow_clients li').size() ) $('#arrow_left_small').show();
	if ( $('#slideshow_clients li').size()>3 && $('#slideshow_clients li').size()-li_pos>3 ) $('#arrow_right_small').show();

	$('#slideshow_clients').mousewheel(function(event, delta){ 
		var kryptis;
		if (delta > 0) {
			if ( $('#arrow_left_small').is(':visible') ) kryptis = 'prev';
		} else {
			if ( $('#arrow_right_small').is(':visible') ) kryptis = 'next';
		}
		if (kryptis) $(this).trigger( kryptis );
		return false;
	});

	$('#slideshow_clients').serialScroll({
		items:'li',
		prev:'#arrow_left_small',
		next:'#arrow_right_small',
		start: li_pos, 
		duration:300,
		step:1,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		jump: false, //click on the images to scroll to them
		onBefore:function( e, elem, $pane, $items, pos ){
			if ( pos==0 ) {
				$('#arrow_left_small').hide();
			} else {
				$('#arrow_left_small').show();
			}
			if ( (pos+3)==$('#slideshow_clients li').size() ) {
				$('#arrow_right_small').hide();
			} else {
				$('#arrow_right_small').show();
			}
			
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});
});