function init()
{
    if( $("div#controller").length>0)
	 {

         $("div#controller").jFlow({
                slides: "#slides",
                width: "100%",
                height: "333px"             

            });

      }
      $(".dropdown dt a").click(function() {
                $(".dropdown dd ul").toggle();
            });                        

     $(".dropdown dd ul li a").click(function() {
                var text = $(this).html();
                $(".dropdown dt a span").html(text);
                $(".dropdown dd ul").hide();
            });

                        

     function getSelectedValue(id) {
                return $("#" + id).find("dt a span.value").html();

            }



     $(document).bind('click', function(e) {
                var $clicked = $(e.target);
                if (! $clicked.parents().hasClass("dropdown"))
                    $(".dropdown dd ul").hide();

            });

     $(".dropdownSecond dt a").click(function() {
                $(".dropdownSecond dd ul").toggle();

            });

                        

     $(".dropdownSecond dd ul li a").click(function() {
                var text = $(this).html();
                $(".dropdownSecond dt a span").html(text);
                $(".dropdownSecond dd ul").hide();

            });

                        

     function getSelectedValue(id) {
                return $("#" + id).find("dt a span.value").html();

            }



     $(document).bind('click', function(e) {
                var $clicked = $(e.target);
                if (! $clicked.parents().hasClass("dropdownSecond"))
                    $(".dropdownSecond dd ul").hide();

            });

     

     if($("#accordion").length>0)
     {
     $("#accordion").accordion({
     header: "h3",
     active: false,    
     collapsible: true });

     }
}

$(document).ready(init);

function toogleDiv(num)
{
    num=num-1;
    $("#accordion").accordion('activate',num);
}

var address = '';
var ps_locations;
var map;
var marker;
var markers = [];
var infowindow;
var infowindow_event=[];
var geocoder;
var bounds;
var google_locations = [];
var gmarkers = []; 


function get_store_locations()
{
	var locations = $('.place .address span.location').html();
	var result = [];
	if(locations.indexOf('|@|')==-1)
	{
        var address = $('.locationAddress');
        var i=0;
        address.each(function() 
        {
            result[i] = $(this).html();
            i++;
        });     

	}
	else
        result= locations.split('|@|');
	if(result.length > 0)
	{
		return result;
	}
	else
	{
		return false;

	}

}
function stripHTML(string)
{

    var matchTag = /<(?:.|\s)*?>/g;
    return string.replace(matchTag, "");

}
function add_marker(latlang, title,html)
{

	marker = (new google.maps.Marker({ 
		position: latlang, 
		map: map,    
		draggable: false, 
		title: stripHTML(title),
		html: html,		 
		animation: google.maps.Animation.DROP	

	}));

	bounds.extend(latlang);
	map.fitBounds(bounds);
	return marker;
}

function myclick(i)
{    

     if(markers[i])
     {
        google.maps.event.trigger(markers[i], "click");         
        location.href="#map";
     }
}



function initialize() {
	if(document.getElementById('gmap'))
	{
		var showCitymap=0;
		if($(".locationOneCity").length>0) showCitymap=1;
		
		if(showCitymap)
		{
            currCity=$(".locationOneCity").html();
            currCity=currCity.split("|");
            
            var currentCity = new google.maps.LatLng(currCity[0],currCity[1]);
            var startup = {
                zoom: 15,
                center: currentCity,
                streetViewControl: false,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("gmap"), startup);
            infowindow = new google.maps.InfoWindow();
		}
		else
		{
		var sofia = new google.maps.LatLng(42.744816, 25.341723);
		var startup = {
			zoom: 10,
			center: sofia,
			streetViewControl: false,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};

		map = new google.maps.Map(document.getElementById("gmap"), startup);
		infowindow = new google.maps.InfoWindow();
		ps_locations = get_store_locations();

        tempinfo=(location.href).split("/");
        langname=tempinfo[3];
        if(!langname) langname='bg';
		if(ps_locations)
		{
			// Initialize bound, geocoder and infowindow:
			geocoder = new google.maps.Geocoder();
			bounds = new google.maps.LatLngBounds();
			infowindow = new google.maps.InfoWindow();	
			addressLocation=new google.maps.LatLng();
			for(i = 0; i < ps_locations.length; i++)
			{
				address = ps_locations[i];
				addressLoc=address.split("|");
				//alert(addressLoc);
				if(addressLoc[0]&&addressLoc[1])
				{                    

                    addressLocation=new google.maps.LatLng(addressLoc[0], addressLoc[1],false); 
                   // alert(addressLoc);
                   
                    if(langname=='bg')  addressTitle=addressLoc[2]+', България';  
                    else addressTitle=addressLoc[2]+', Bulgaria';                   
                    if(addressLoc[3]) addressHtml=addressTitle+'<br /><a href="/'+langname+'/hospitals/'+addressLoc[3]+'/" style="text-decoration:underline;color: #F20000;">'+(langname=='bg' ? 'лечебни заведения' : 'hospitals')+' &raquo;</a>';
                    else addressHtml=addressTitle;
					var tmp_marker = add_marker(addressLocation, addressTitle,addressHtml);
					markers.push(tmp_marker);					

			   }

			}
			for(var i=0;i<markers.length;i++)
			{

					google.maps.event.addListener(markers[i], 'click', function() 
					{
							infowindow.setContent(this.html);
							infowindow.open(map, this);							

					}); // for loop
			}

		} // if ps_locations is true
		}

	} // end if gmap exists
	

}
