$(document).ready(function(){
	if(typeof(activatePage)=="function") {
	    activatePage();
	}
	$('nav li a').each(function() {
        $(this).parent().eq(0).hoverIntent({
            timeout: 400,
            over: function() {
                var current = $('ul', this);
                if(current.children('li').length > 0){
                    current.siblings('a').addClass('navShow');
                    current.fadeIn(200);
                }
            },
            out: function() {
                var current = $('ul', this);
                if(current.children('li').length > 0){
                    current.siblings('a').removeClass('navShow');
                    current.fadeOut(200);
                }
            }
        });
    });
    
    $('img.caption').each(function(){
        var image = $(this);
        var caption = image.attr('title');
        var width = (image.width() - 40) + 'px';
        var height = (image.height() - 20) + 'px';
        image.wrap('<span class="rollover" />');
        image.after('<span class="captionText" style="width:'+ width +'; height:'+ height +';">'+ caption +'</span>');
        
        image.parent('.rollover').mouseenter(function(){
            $(this).children('.captionText').fadeIn(400);
         }).mouseleave(function(){
            $(this).children('.captionText').fadeOut(400);
         });
    });
    
    if($('#content.home').length > 0){
        $('#left-panel').animate({left:'-30'}, 1000, function(){
             $f("homeVideo", "/assets/videos/flowplayer-3.2.5.swf", {
                clip: {
                    onBeforeFinish: function(){ return false }
                }
             });
        });
        $('#right-panel').animate({left:'-30'}, 1000);
    }
    
    if($('#map-holder').length > 0){
        $('#map-holder').gMap({
                  markers: [{ latitude: 51.516235,
                              longitude: -0.217481,
                              icon: { image: "/assets/images/jbPin.png",
                                      iconsize: [93, 104],
                                      iconanchor: [30,104],
                                      infowindowanchor: [12, 0] } }],
                  icon: { image: "/assets/images/images/jbPin.png", 
                          iconsize: [93, 104],
                          iconanchor: [12, 46],
                          infowindowanchor: [12, 0] },
                  latitude: 51.516235,
                  longitude: -0.217481,
                  zoom: 15 });
                  
        $('.locate').bind('click',function(){
            var lati = $(this).attr('lat');
            var longi = $(this).attr('long');
            var loc = $(this).attr('loc');
            var pin = 'jbPin.png';
            
            if(loc == "Shanghai"){
                var pin = 'jbsPin.png';
            }
            if(loc == "Japan"){
                var pin = 'jbjPin.png';
            }
            
            $('#map-holder').gMap({
                  markers: [{ latitude: lati,
                              longitude: longi,
                              icon: { image: "/assets/images/"+pin,
                                      iconsize: [93, 104],
                                      iconanchor: [30,104],
                                      infowindowanchor: [12, 0] } }],
                  icon: { image: "/assets/images/images/jbPin.png", 
                          iconsize: [93, 104],
                          iconanchor: [12, 46],
                          infowindowanchor: [12, 0] },
                  latitude: lati,
                  longitude: longi,
                  zoom: 15 });
        });          
    }
    
     if($('#videoPlayer').length > 0){
        $f("videoPlayer", "/assets/videos/flowplayer-3.2.5.swf");
     }
     
     if($('.videoPlayer').length > 0){
        $('.videoPlayer').flowplayer("/assets/videos/flowplayer-3.2.5.swf", {clip:{autoPlay:true}});
     }
     
    if($('.videoPlayerNoAutoPlay').length > 0){
        $('.videoPlayerNoAutoPlay').flowplayer("/assets/videos/flowplayer-3.2.5.swf", {clip:{autoPlay:false}});
     }
     
     $('#work li a').mouseenter(function(){
        $(this).children('img').eq(1).fadeIn(400);
     }).mouseleave(function(){
        $(this).children('img').eq(1).fadeOut(400);
     });
     
     
      
	
});
