var gmapsactive;
$(document).ready(function(){

 $(function(){
	  $("#loopedslider").loopedSlider({ autoStart: 3500 });
  });

if (gmapsactive)
initialize_gmaps();

lc = window.location.href;
pos = lc.indexOf("#");
  var pa = lc.substr(pos+1);
if (pos!="-1" & pa!="")
{
  if (pa == "intermap")
    show_intermap();
  else
  gotocity(pa);
}

$("#ajform").ajaxForm(function() {
$("#ajform_sent").css('display','block');
$("#ajform").css('display','none');
});

$("Map area, .contact_map_city a").click(
function()
{
id=$(this).attr("city");
gotocity(id);
window.location = "#"+id;
}
);

$("#contact_mapstyle_inter").click(
function()
{
    show_intermap();
}
);

$("#contact_mapstyle_normal").click(
function()
{
$("#contact_map_region").attr("src", function() {
          return "/img/map/regions/clr.png";
        });
window.location = "#";
$("#map_reglay").css('visibility','');
$("#map_img").css('visibility','');
$("#map_inter").css('display','none');
$("#contact_mapstyle_inter").removeClass("contact_mapstyle_s_act").addClass("contact_mapstyle_s");
$("#contact_mapstyle_normal").removeClass("contact_mapstyle_s").addClass("contact_mapstyle_s_act");

}
);

$(".style_top_lang a").click(
function()
{
  $.post('/set_lang/'+$(this).attr("lang"), function(data) {
location.reload();
});

}
);


$(".poll_radio").click(
function()
{
  if ($(this).attr("value"))
  {
    $.post('/poll_vote/'+$(this).attr("value"), function(data) {
    location.reload();
    });
  }
}
);

$("#goods_size").change(function () {
$(".goods_cost").text($("#goods_size :selected").attr("cost"));
        })

$(".goods_photo_thumb").click(function () {
$(".goods_photo_full").html('<img src="/img/base/'+$(this).attr("img_id")+'.jpg">');
        })



});


function gotocity(id){
$("#contact_map_region").attr("src", function() {
          return "/img/map/regions/"+id+".png";
        });

        $.getJSON('/map_normal/'+id, {}, function(json){
            $('#contact_stores').html('');
            $('#contact_stores').append(json.note);
            initialize_gmaps();
        });
}


function initialize_gmaps() {
 if (GBrowserIsCompatible()) {

 $(".map_canvas").each(function(){
 var map = new GMap2($(this).get(0));
 map.setCenter(new GLatLng($(this).attr("lat")
, $(this).attr("long")), 13);
var marker = new GMarker(new GLatLng($(this).attr("lat")
, $(this).attr("long")));
map.addOverlay(marker);
})

 }
 }
 
function initialize_gmaps_map_inter() {

if (GBrowserIsCompatible()) {
var map = new GMap2($("#map_inter").get(0));
map.addControl(new GLargeMapControl());
map.setCenter(new GLatLng('48.5','31'),6);

$.getJSON('/map_inter/', {}, function(json){

$.each(json.markers, function()
{
  var marker = new GMarker(new GLatLng(this.lat, this.long));
  map.addOverlay(marker);
  var id = this.id;
GEvent.addListener(marker, "click", function() {
        $.getJSON('/map_inter_stor/'+id, {}, function(json){
            $('#contact_stores').html('');
            $('#contact_stores').append(json.note);
            initialize_gmaps();
        });
        });
});
});
}
}

function show_intermap(){
window.location = "#intermap";
$("#map_reglay").css('visibility','hidden');
$("#map_img").css('visibility','hidden');
$("#map_inter").css('display','');
$("#contact_mapstyle_normal").removeClass("contact_mapstyle_s_act").addClass("contact_mapstyle_s");
$("#contact_mapstyle_inter").removeClass("contact_mapstyle_s").addClass("contact_mapstyle_s_act");

initialize_gmaps_map_inter();
$('#contact_stores').html('');
}


var params = {
		changedEl: "#country",
		visRows: 7
	}
	cuSel(params);


  hs.graphicsDir = 'js/hs/graphics/';
	hs.transitions = ['expand', 'crossfade'];
	hs.fadeInOut = true;
	hs.align = 'center';
	hs.showCredits = false;
