$(function(){


menu.init();
slideshow.init();

$('#footer .facebook,#footer .twitter,#footer .rss').tooltip({fixedOnElement:true,fontSize:'12px',dartInCenter:true,backgroundColor:'#f2f7fb',border:'1px solid #9bc4e1',useCSS3shadow:true,CSS3shadow:'0 5px 15px rgba(0,0,0,0.4)',alwaysTop:true});


});



var menu={
  cont:null,
  line:null,
  timer:null,
  init:function(){
    var self=this;
    this.cont=$('#menu');
    
    this.line=$('<div class="line"></div>').appendTo(this.cont);
    var current=this.cont.find('.current');
    if(current){
      current=current.get(0);
    }

    this.cont.find('a').mouseover(function(){
      var el=this;
      clearTimeout(self.timer);
      self.timer=setTimeout(function(){self.set(el)},50);
    }).mouseout(function(){
      var el=this;
      clearTimeout(self.timer);
      self.timer=setTimeout(function(){self.set(current)},100);

    });

    this.set(current);
  },

  set:function(el){
    if(!el){
      this.line.fadeOut(200,function(){$(this).hide()});
      return;
    };
    var li=$(el).parent('li').eq(0),index=0;
    while(li.prev('li').length!=0){
      li=li.prev('li');
      index++;
    }
    var l=$(el).position().left+parseInt($(el).css('padding-left'),10);
    var w=$(el).width();
    if(this.line.is(':visible')){
      this.line.stop();
      this.line.animate({width:w,left:l,opacity:1},200)
    }else{
      this.line.css({width:w,left:l}).fadeIn(200);
    }
  }
};


var slideshow={
  init:function(){
    var data=$('.slideshow-data a');
    if(data.length>0){
      var options={data:[]};
      data.each(function(i,el){
        var tab={};
        tab.link=el.href;
        tab.image=$(el).find('img').eq(0).attr('src');
        tab.name=$(el).find('.name').eq(0).html();
        options.data.push(tab);
      });
      $('.slideshow-in').slideshow(options);
    }
  }
};



// google api

function createMarker(point,html) {
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	return marker;
}

function createMap(){
	var map = new GMap2(document.getElementById("map"));
	map.setUIToDefault();

/*
  map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
*/
	//map.setMapType(G_HYBRID_MAP);
	return map;
}

function addPointer(map,html,lat,lng){
	var point = new GLatLng(lat,lng);
	var marker = createMarker(point,html)
	map.addOverlay(marker);
	return marker;
}

function addGoogleMap(lat,lng,html,zoom,lat_center,lng_center){
 if (GBrowserIsCompatible()) {
	if(!lat_center)lat_center=lat;
	if(!lng_center)lng_center=lng;
	$(window).load(function(){
		var map = createMap();

		var marker = addPointer(map,html,lat,lng);
		GEvent.trigger(marker, "click");

		map.setCenter(new GLatLng(lat_center,lng_center),zoom);


		$(window).unload=function(){GUnload()}
	});
 }
}

function decorate(){
  var a;
  if($.browser.msie && parseInt($.browser.version,10) == 7)a="IE7";
  else if($.browser.msie && parseInt($.browser.version,10) == 8)a="IE8";

  if(a) $('html').addClass(a);
}
decorate();

