var maps;(function($)
{
    $(function()
    {
        // Firefox .btn style fix
        if ($.browser.mozilla)
            $("input[type='submit'], input[type='button']").css('padding-bottom', '3px');
        
        
        $(".translations_list .item a").hover(
            function()
            {
                $(".flag_cnt", this).css({
                    background: 'url(images/flag_bg_active.gif) no-repeat'
                });
            },
            function()
            {
                $(".flag_cnt", this).css({
                    background: 'url(images/flag_bg.gif) no-repeat'
                });
            }
        );
        
        // This is another fix for IE6 quirks
        // if ($.browser.msie && $.browser.version < 7.0)
        // {
            // $(".translations_list .item .flag_cnt").each(function()
            // {
                // $(this).data('orig_position_top', $(this).position().top);
            // });
            
            // $(window).resize(function()
            // {
                // $(".translations_list .item .flag_cnt").each(function()
                // {
                    // $(this).css({
                        // top: $(this).data('orig_position_top')
                    // });
                // });
            // });
        // }
        
        function position_visible_translations_list_item(item)
        {
            var pos_top     = $("a", item).offset().top -  $(".balloon", item).height() - 25;
            var pos_left    = $("a", item).offset().left - ($(".balloon", item).outerWidth() / 2)
                + ($("a", item).outerWidth() / 2);
            
            if (pos_top < 10)
                pos_top = 10;
            if (pos_left < 10)
                pos_left = 10;
            if (pos_left + $(".balloon", item).outerWidth() > $(window).width() - 10)
                pos_left = $(window).width() - 10 - $(".balloon", item).outerWidth();
            
            $(".balloon", item).css({
                top: pos_top,
                // marginLeft: - ($(".balloon", item).outerWidth() / 2)
                    // + ($("a", item).outerWidth() / 2)
                left: pos_left
            });
            
            // if ($(".balloon", item).offset().left < 0)
                // $(".balloon", item).css({
                    // marginLeft: $(".balloon", item).css('marginLeft').replace(/px/, '')
                        // - $(".balloon", item).offset().left
                // });
        }
        
        function show_translations_list_item(item)
        {
            // var hide_afterwards = false;
            // if ($(".balloon", item).is(":visible") == false)
            // {
                // // $(".balloon", item).css('opacity', 0.51);
                
                
                
                // hide_afterwards = true;
            // }
            
            // $(".balloon", item).fadeTo(0, 0.01, function()
            // {
                // position_visible_translations_list_item(item);
                // $(".balloon", item).fadeTo(400, 1.0);
            // });
            
            position_visible_translations_list_item(item);
            $(".balloon", item).fadeIn()
        }
        
        $(window).resize(function()
        {
            $(".translations_list .item").each(function()
            {
                if ($(".balloon", this).is(":visible"))
                    position_visible_translations_list_item($(this));
            });
        });
        
        $(".translations_list .item").each(function()
        {
            var item = $(this);
            
            $(".balloon .close", item).click(function()
            {
                $(".balloon", item).fadeOut();
            });
            
            $(".balloon", item).hover(
                function()
                {
                    $(this).data('mouse_over', true);
                },
                function()
                {
                    $(this).data('mouse_over', false);
                }
            );
            $("a", this).click(function()
            {
                if ($(".balloon", item).is(":visible"))
                    $(".balloon", item).fadeOut();
                else
                {
                    $(".translations_list .item .balloon").fadeOut();
                    // $(".balloon", item).fadeIn();
                    show_translations_list_item(item);
                    $(document).click(function()
                    {
                        if (! $(".balloon", item).data('mouse_over'))
                            $(".balloon", item).fadeOut();
                    });
                }
                
                return false;
            });
        });
		$(".ctitle").click(function(e){
			$(this).hide();			
			var cbody = $(this).next('.cbody');
			if(!cbody.find('.cbodytitle').size()){
				cbody.show();
				cbody.hide();
				cbody.prepend('<div class="cbodytitle">'+$(this).html()+'</div>');
			}
			cbody.show();
		});					
		$(".cbody").click(function(e){
			if($(e.target).hasClass('cbodytitle')){
				$(this).hide();
				$(this).prev('.ctitle').show();	
			}	
		});			
		$(".idaugiau").click(function(e){		
			$(this).next(".pcontent").html();		
			var daukstis = getDocHeight();
			
			$.floatbox({
				content: $(this).next(".pcontent").html(),
				aukstis: daukstis,			
				plotis: '960',			
				mright: '0',			
				fade: true		
				});	    
			});
			$(".daugiaufbd").click(function(e){
				$('.fbs, .daugiaufbm').show();		
				$(this).hide();	
			});	
			$(".daugiaufbm").click(function(e){		
				$('.daugiaufbd').show();		
				$(this).hide();		
				$(".fbs").hide();			
			});				    
		});
	})(jQuery);
	function koo(name){	  
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");	  
		var regexS = "[\\?&]"+name+"=([^&#]*)";	  
		var regex = new RegExp( regexS );	  
		var results = regex.exec( window.location.href );	  
		if( results == null )		return "";	  else		return results[1];	
		}	
	function CreateGMap2010030223144(){		
		if(!GBrowserIsCompatible()) return;		
		var allMapTypes = [G_NORMAL_MAP, G_HYBRID_MAP] ;		
		var map = new GMap2(document.getElementById("gmap2010030223144"), {mapTypes:allMapTypes});		
		var vieta=new Array(); 		
		vieta[0]= new Array();		
		vieta[0]['lon']=mapi.lon;		
		vieta[0]['lat']=mapi.lat;		
		vieta[0]['text']='';		
		vieta[0]['zoom']=mapi.zoom;		
		vieta[1]= new Array();		
		vieta[1]['lon']=mapi.lon;		
		vieta[1]['lat']=mapi.lat;		
		vieta[1]['text']=mapi.text;		
		vieta[1]['zoom']=mapi.zoom;		
		map.setCenter(new GLatLng(vieta[0]['lon'],vieta[0]['lat']),vieta[0]['zoom']);		
		map.setMapType( allMapTypes[0] );		
		map.addControl(new GSmallMapControl());		
		map.addControl(new GMapTypeControl());		
		AddMarkers(map, [{lat:vieta[1]['lon'], lon:vieta[1]['lat'], text:vieta[1]['text'], kuris:'1'}] ) ;	
		}
		function AddMarkers( map, aPoints ){
			var myIcon = new GIcon();		
			myIcon.image = '/images/mapslogo.png';		
			myIcon.shadow = '/images/mapsshadow.png';		
			myIcon.iconSize = new GSize(149,56);		
			myIcon.shadowSize = new GSize(181,56);		
			myIcon.iconAnchor = new GPoint(0,56);		
			myIcon.infoWindowAnchor = new GPoint(80,0);		
			myIcon.imageMap = [140,8,140,9,140,10,140,11,140,12,140,13,140,14,140,15,140,16,140,17,140,18,140,19,140,20,140,21,140,22,140,23,140,24,140,25,140,26,140,27,140,28,140,29,140,30,140,31,140,32,140,33,140,34,140,35,140,36,140,37,140,38,140,39,140,40,140,41,140,42,140,43,140,44,140,45,140,46,12,47,11,48,10,49,9,50,8,51,7,51,6,50,5,49,4,48,3,47,2,46,2,45,2,44,2,43,2,42,2,41,2,40,2,39,2,38,2,37,2,36,2,35,2,34,2,33,2,32,2,31,2,30,2,29,2,28,2,27,2,26,2,25,2,24,2,23,2,22,2,21,2,20,1,19,0,18,2,17,2,16,2,15,2,14,2,13,2,12,2,11,2,10,2,9,2,8,140,8];		
			var markerOptions = {icon:myIcon};		
			for (var i=0; i<aPoints.length ; i++){			
				var point = aPoints[i] ;			
				map.addOverlay( createMarker(new GLatLng(point.lat, point.lon), point.text, point.kuris, markerOptions) );		}	
			}
			function createMarker( point, html, kuris, markerOptions ){		
				var marker = new GMarker(point,markerOptions );		
				var db=koo('m');		
				var from_html = mapi.lang1+'<form action="http://maps.google.com/maps" method="get" target="_blank">' + '<input type="text"  MAXLENGTH=48 name="saddr" id="daddr" value=""  style="font-size:10px; width: 180px" /><br>' + '<INPUT value="'+mapi.lang2+'" TYPE="SUBMIT" style="font-size:10px">' + '<input type="hidden" name="hl" value="lt"><input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + '" /></form>';		
				var tb=koo('t');		
				if (tb == "") tb=0;		
				var aurl = window.location.protocol + "//" + window.location.host + "" + window.location.pathname+"?";		
				var turl = mapi.lang4+"?";		
				html = html+'<br /><br /><a href="'+aurl+'m='+kuris+'&t=1">'+turl+'</a>';		
				var tab1 = new GInfoWindowTab(mapi.lang3, html);		
				var tab2 = new GInfoWindowTab(mapi.lang4, from_html);		
				GEvent.addListener(marker, "click", function() {			
					marker.openInfoWindowHtml(html, {maxWidth:200});			
					marker.openInfoWindowTabsHtml([tab1,tab2]);		
				});		
				if (db == kuris){		
					marker.openInfoWindowHtml(html, {maxWidth:200});			
					marker.openInfoWindowTabsHtml([tab1,tab2], {selectedTab:tb});		
				}		
				return marker;	
			}
	function dump(arr,return_text,level,objs_dumped) {
    if (return_text == undefined) return_text = false;
    var dumped_text = "";
    if(!level) level = 0;
    if (objs_dumped == undefined) objs_dumped = [];
    
    //The padding given at the beginning of the line.
    var level_padding = "";
    for(var j=0;j<level+1;j++) level_padding += "    ";
    
    if(typeof(arr) == 'object') { //Array/Hashes/Objects 
        for(var item in arr) {
            try {
                var value = arr[item];
                if(typeof(value) == 'object') { //If it is an array,
                    dumped_text += level_padding + "'" + item + "' ...\n";
                    // Recursion protection
                    var already_dumped = false;
                    for (var k = 0; k < objs_dumped.length; k++)
                        if (value == objs_dumped[k]) {
                            already_dumped = true;
                            dumped_text += 'recursion! (already dumped somewhere above)\n';
                        }
                    if (already_dumped == false) {
                        objs_dumped[objs_dumped.length] = value;
                        dumped_text += dump(value,true,level+1,objs_dumped);
                    }
                } else {
                    dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
                }
            } catch (err) {}
        }
    } else { //Stings/Chars/Numbers etc.
        dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
    }
    
    if (return_text)
        return dumped_text;
    else
        alert(dumped_text);
}
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

