     
$(document).ready(function(){
  dynamiseSceneNormal();        
});





function dynamiseSceneNormal(){
 
 $(".scene_normal_block").each(function(){
     var sc = $(this);
     var btn_view_more = sc.find(".view_more_button");
     var link =  btn_view_more.attr("href");
     var id =  parseInt(sc.attr("id").replace("scene_", ""));                                      
     //Bind Click function to other element
     
     sc.find("div.scene_normal").mouseover(function() {
        $(this).find('.overlay_normal_text span').css('color', '#ffde00')
     }).mouseout(function() {
        $(this).find('.overlay_normal_text span').css('color', 'white')
     })
     
     if($("#player").size() == 1)
     {
        sc.find("div.scene_normal, a:not('.btn_join')").click(widgetCallPlayer);      
        $("a.scene_by_day").click(rightNavCallPlayer);   
     }
     else
     {
        sc.find("div.scene_normal").click(function(){document.location = link;return false;});     
     }
     
    for(var v = 0; v < viewedScenes.length; v++)
    {   
        if(viewedScenes[v] == id){
            var widget = sc;          
            widget.data("viewed", true);
            widget.find(".btn_viewmore").hide();         
            widget.find(".btn_join").show();     
            widget.find(".btn_replay").show();   
        }
    }  
     
 }); 
 
}                     
          
/**
* @desc Function that talk to the player 
*/
function widgetCallPlayer(){  
    
    var sceneWidget = $(this).parents(".scene_normal_block");
    
    var params = sceneWidget.attr("id").split("_");
    var id = params[params.length - 1];  
    
    // Make that widget active and unactive the other one       
        $(".current").removeClass("current");
        sceneWidget.addClass("current");       
    
    // Update the Player Directly
    if($(this).is(".scene_normal"))
    {
        updatePlayer(id, 0, 0);
    }
    if($(this).is("a")){
        updatePlayer(id, 0, 1);     
    }
    
    //Update the Scene Title
        var scene_name = sceneWidget.find(".scene_normal_title_text a").html().replace("-", " ");
        var scene_title = sceneWidget.find(".overlay_normal_text span").html().replace("-", " ");
        $(".player_info").attr("id", "current-scene_" + id); 
        $(".player_info span").html(scene_name + " - " + scene_title);
    
    //Scroll to the player
        $.scrollTo(0, 500);  
        
    //Set as Viewed
        addScenesView(id);  
        
           sceneWidget.data("viewed", true);
           sceneWidget.find(".btn_viewmore").hide();         
           sceneWidget.find(".btn_join").show();     
           sceneWidget.find(".btn_replay").show();   
    
        
    
    return false; 
}


function rightNavCallPlayer()
{     
    
    var params = $(this).attr("id").split("_");
    var params2 = $(this).attr("href").split("/");
    
   
    var id = params[params.length - 1];         
    
    sceneWidget = $("#scene_" + id);
    // Make that widget active and unactive the other one       
        
    
    $(".current").removeClass("current");
    sceneWidget.addClass("current");       
    
    // Update the Player Directly
    if($(this).is(".scene_normal"))
    {
        updatePlayer(id, 0, 0);
    }
    if($(this).is("a")){
        updatePlayer(id, 0, 1);     
    }
    
    //Update the Scene Title
        var scene_name = params2[2].replace("-", " ");;
        var scene_title = params2[3].replace("-", " ");;
        $(".player_info").attr("id", "current-scene_" + id); 
        $(".player_info span").html(scene_name + " - " + scene_title);
    
    //Scroll to the player
        $.scrollTo(0, 500);   
    
    return false;  
}



