
function createSilverlight()
{
	var scene = new REMIX_phase2.Scene();
	
	Silverlight.createObjectEx({
		source: 'Scene.xaml', 
		parentElement:document.getElementById("SilverlightControlHost"),
		id:'SilverlightControl', 
		properties:{
			width:'100%', 
			height:'100%', 
			isWindowless:'false', 
			enableFramerateCounter:false, 
			inplaceInstallPrompt:true,
			version:'0.9'
		},
		events:{
			onError:null, onLoad:Silverlight.createDelegate(scene, scene.handleLoad), onResize:null
		}, 
		context:null}
	);
	
	
}


if (!window.Silverlight) 
	window.Silverlight = {};

Silverlight.createDelegate = function(instance, method) {
	return function() {
        return method.apply(instance, arguments);
    }
}

function SetEventListener(target, event, handler, owner ){
    sender.findName(target).addEventListener(event,Silverlight.createDelegate(owner, handler))
}
function SetEventListeners(target, events, owner){
    for(var name in events ){
        var handler = events[name];
        SetEventListener(target,name,handler,owner);
    }
}
function Page_Loaded(object,args){
    sender = object;
    silverlightContents.StartLoadOpening();
    silverlightContents.SetResizeHandle();
    silverlightContents.SetHandler();    
}

var sender;
var bgCanvas;
createSilverlight.prototype = {
    StartLoadOpening : function(){
//        this.loader = new Loader("./files.deploy","loading_bar","percent",300,this.CompOpeningLoaded);
        this.loader = new Loader("./files.deploy",undefined,undefined,300,this.CompOpeningLoaded);
        this.loader.StartLoader();
    },
    CompOpeningLoaded : function(){
        BeginStoryboard("AnimLoadCompleted");
    },
    HandleFinLoadCompleted : function(sender, e){
        this.mediaContents = new MediaControl();
        this.SetImages();
        
        SetVisibility(sender.findName("loader"),false);
        
        BeginStoryboard("AnimShow");
        
        this.btnsRoot = sender.findName("_btns_root");
        this.btnsChild  = sender.findName("_btns_child");
        this.SetResizeHandle();
    },
    SetResizeHandle : function(){
        bgCanvas = sender.findName("parentCanvas");
        //window.onresize = this.HandleOnResize;
        sender.getHost().content.onResize = this.HandleOnResize;
        this.HandleOnResize();
    },
    HandleOnResize : function(){
        var content = document.getElementById("SilverlightControlHost");
        var clientH = document.body.clientHeight;
        var clientW = document.body.clientWidth;
        bgCanvas.SetValue('Canvas.Top',Math.round(clientH / 2 - bgCanvas.Height / 2));
        bgCanvas.SetValue('Canvas.Left',Math.round(clientW / 2 - bgCanvas.Width / 2));
    },
    HandleOverBtn : function(sender, args){
        BeginStoryboard("AnimOver" + sender.name);
    },
    HandleOutBtn : function(sender, args){
        BeginStoryboard("AnimOut" + sender.name);
    },
    HandleOverChildBtn : function(sender,args){
        sender = sender.findName((sender.name).substring(6));
        this.HandleOverBtn(sender, args);
    },
    HandleOutChildBtn : function(sender,args){
        sender = sender.findName((sender.name).substring(6));
        this.HandleOutBtn(sender, args);
    },
    HandleReleaseGnaviBtn : function(sender, args){
        this.targetContents = sender.name.substring(5);
        this.mediaContents.HandleReleaseMediaStop(sender, args);
        this.HandleShowRootBtns(false);
        BeginStoryboard("AnimChgPageToChild");
    },
    HandleCompChgPageToChild : function(sender, args){
        if(this.target != undefined){
            SetVisibility(this.target,false);
        }
        this.target = sender.findName("child_contents_" + this.targetContents);
        this.ShowDetailBtn();
        SetVisibility(this.target,true);
        BeginStoryboard("AnimShowChildContents");
    },
    HandleCompShowChildContents : function(sender, args){
        this.contentsBtn = sender.findName("_btn_child_contents_"+this.targetContents);
        this.HandleShowChildBtns(true);
        SetVisibility(this.contentsBtn,true);
    },
    ShowDetailBtn : function(){
        if(this.targetContents == "about" || this.targetContents == "conference"){
            if(this.detail_text != undefined){
                SetVisibility(this.detail_text,false);
                SetVisibility(this.detail_bg,false);
            }
            if(this.targetContents == "about"){
                this.detail_text = "btn_detail_about";
                this.detail_bg = "btn_detail_bg_about";
            }else{
                this.detail_text = "btn_detail_conference";
                this.detail_bg = "btn_detail_bg_conference";
            }
            
            this.btnDetail = sender.findName("_btn_detail_" + this.targetContents);
            SetVisibility(this.btnDetail,true);
            
            this.detail_text = sender.findName(this.detail_text);
            this.detail_bg = sender.findName(this.detail_bg);
            
            SetVisibility(this.detail_text,true);
            SetVisibility(this.detail_bg,true);
            
            BeginStoryboard("AnimShowBtnDetail");
        }
    },
    HandleReleaseGnaviBtnChild : function(sender, args){
        this.targetContents = sender.name.substring(11);

        BeginStoryboard("AnimHideChildContents");
        BeginStoryboard("AnimHideBtnDetail");

        if(this.btnDetail != undefined){
            SetVisibility(this.btnDetail,false);
        }
        
        if(this.contentsBtn != undefined){
            SetVisibility(this.contentsBtn,false);        
        }
    },
    HandleCompHideChildContents : function(sender, args){
        if(this.targetContents == "totop"){
            this.HandleShowChildBtns(false);
            BeginStoryboard("AnimChgPageToTop");
        }else{
            this.HandleCompChgPageToChild(sender,args);
        }
    },
    HandleCompChgPageToTop : function(sender, args){
        this.HandleShowRootBtns(true);
    },
    HandleReleaseDetailBtn : function(sender, args){
        SetVisibility(sender.findName("detail"),true);
        BeginStoryboard("AnimShowDetail_"+this.targetContents);
    },
    HandleCompShowDetail : function(sender, args){
        SetVisibility(sender.findName("_btn_sub_"+this.targetContents),true);
    },
    HandleReleaseDetailCloseBtn : function(sender, args){

        SetVisibility(sender.findName("_btn_sub_"+this.targetContents),false);
        BeginStoryboard("AnimHideDetail_"+this.targetContents);
    },
    HandleCompHideDetail : function(sender, args){
        SetVisibility(sender.findName("detail"),false);
    },
    HandleOverChildContentsBtn : function(sender,args){
        var id = sender.name.substring(20);
        sender.findName("child_contents_" + id).opacity = 1;
    },
    HandleOutChildContentsBtn : function(sender,args){
        var id = sender.name.substring(20);
        sender.findName("child_contents_" + id).opacity = 0;
    },
    HandleShowRootBtns : function(flg){
        if(flg){
            SetVisibility(this.btnsRoot,true);
        }else{
            SetVisibility(this.btnsRoot,false);
        }
    },
    HandleShowChildBtns : function(flg){
        if(flg){
            SetVisibility(this.btnsChild,true);
        }else{
            SetVisibility(this.btnsChild,false);
        }
    },
    SetImages : function(){
        var target = this.loader.downLoader.findName("bg_");
        target.setSource(this.loader.downLoader, "imgs/bg.jpg");
        
        target = this.loader.downLoader.findName("bg_child");
        target.setSource(this.loader.downLoader, "imgs/bg_child.jpg");
        
        target = this.loader.downLoader.findName("media_loader_");
        target.setSource(this.loader.downLoader, "media/media_loader.wmv");
    },
    HandleReleaseDetailAboutBtn : function(sender,args){
        var id = sender.name.substring(14);
        var url;
        switch(id){
            case "1":
                url = "http://www.t-i-forum.co.jp/";
                OpenWindow(url,1);
                break;
            case "2":
                url = "http://www.t-i-forum.co.jp/function/map/index.html"
                OpenWindow(url,1);
                break;
            case "3":
                url = "conference/sessionlist_p.aspx";
                OpenWindow(url,2);
                break;
            case "4":
                this.HandleReleaseDetailCloseBtn(sender, args);
                this.HandleReleaseGnaviBtnChild(sender.findName("_child_btn_conference"),args);
                break;
            case "5":
                this.HandleReleaseDetailCloseBtn(sender, args);
                this.HandleReleaseGnaviBtnChild(sender.findName("_child_btn_innovation"),args);
                break;
            case "6":
                this.HandleReleaseDetailCloseBtn(sender, args);
                this.HandleReleaseGnaviBtnChild(sender.findName("_child_btn_night"),args);
                break;
        }
    },
    /*HandleReleaseChildContentsBtn_conference : function(sender, args){
        var id = sender.name.substring(sender.name.length-1);
        var url = this.linkAry_conference[id];
        OpenWindow(url,2);
    },*/
    HandleReleaseChildContentsBtn_conference : function(sender, args){
        var id = sender.name.substring(sender.name.length-1);
        var url = this.linkAry_conference[id][0];
        OpenWindow(url,this.linkAry_conference[id][1]);
    },
    HandleReleaseChildContentsBtn_innovation : function(sender, args){
        var id = sender.name.substring(sender.name.length-1);
        var url = this.linkAry_innovation[id];
        OpenWindow(url,2);
    },
    HandleReleaseChildContentsBtn_fun : function(sender, args){
        var id = sender.name.substring(sender.name.length-1);
        var url = this.linkAry_fun[id][0];
        OpenWindow(url,this.linkAry_fun[id][1]);
    },
    
    HandleReleaseContentsBtn_information : function(sender, args){
        var id = sender.name.substring(sender.name.length-1);
        var url = this.linkAry_information[id][0];
        OpenWindow(url,this.linkAry_information[id][1]);
    },
    
    HandleReleaseChildContentsBtn_partners : function(sender, args){
        var id = sender.name.substring(28);
        var url = this.linkAry_partners[id];
        OpenWindow(url,1);
    },
    HandleReleaseDetailBtnConference : function(sender, args){
        var url = "conference/sessionlist_p.aspx";
        OpenWindow(url,2);
    },
    HandleReleaseChildContentsBtn_link : function(sender, args){
        var id = sender.name.substring(sender.name.length-1);
        var url = this.linkAry_link[id];
        OpenWindow(url,1);
    },
    HandleReleaseFooterBtn : function(sender, args){
        var id = sender.name.substring(11,12);
        var url = this.linkAry_footer[id];
        OpenWindow(url,1);
    },
    HandleReleaseApplyBtn : function(sender, args){
        //var url = "https://www.event-registration.jp/event-profile/events/remix07/";
        var url = "conference/sessionlist_p.aspx";
        OpenWindow(url,1);
    },

    SetHandler : function(){
        SetEventListener("AnimLoadCompleted","completed",this.HandleFinLoadCompleted,this);
        SetEventListener("AnimChgPageToChild", "completed",this.HandleCompChgPageToChild,this);
        SetEventListener("AnimChgPageToTop", "completed",this.HandleCompChgPageToTop,this);
        SetEventListener("AnimShowChildContents", "completed",this.HandleCompShowChildContents,this);
        SetEventListener("AnimHideChildContents", "completed",this.HandleCompHideChildContents,this);
        SetEventListener("AnimShowDetail_about", "completed",this.HandleCompShowDetail,this);
        SetEventListener("AnimHideDetail_about", "completed",this.HandleCompHideDetail,this);
        SetEventListener("_btn_detail_about", "mouseLeftButtonUp",this.HandleReleaseDetailBtn,this);
        SetEventListener("_btn_detail_conference", "mouseLeftButtonUp",this.HandleReleaseDetailBtnConference,this);
        SetEventListener("_btn_sub_about_close", "mouseLeftButtonUp",this.HandleReleaseDetailCloseBtn,this);
        SetEventListeners("_btn_apply", {"mouseEnter" : this.HandleOverBtn,"mouseLeave" : this.HandleOutBtn,"mouseLeftButtonUp" : this.HandleReleaseApplyBtn},this);
        SetEventListeners("_btn_about", {"mouseEnter" : this.HandleOverBtn,"mouseLeave" : this.HandleOutBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtn},this);
        SetEventListeners("_btn_conference", {"mouseEnter" : this.HandleOverBtn,"mouseLeave" : this.HandleOutBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtn},this);
        SetEventListeners("_btn_innovation", {"mouseEnter" : this.HandleOverBtn,"mouseLeave" : this.HandleOutBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtn},this);
        SetEventListeners("_btn_night", {"mouseEnter" : this.HandleOverBtn,"mouseLeave" : this.HandleOutBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtn},this);
        SetEventListeners("_btn_partners", {"mouseEnter" : this.HandleOverBtn,"mouseLeave" : this.HandleOutBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtn},this);
        SetEventListeners("_btn_fun", {"mouseEnter" : this.HandleOverBtn,"mouseLeave" : this.HandleOutBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtn},this);
        SetEventListeners("_child_btn_about", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        SetEventListeners("_child_btn_conference", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        SetEventListeners("_child_btn_innovation", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        SetEventListeners("_child_btn_night", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        SetEventListeners("_child_btn_about", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        SetEventListeners("_child_btn_fun", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        SetEventListeners("_child_btn_partners", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        SetEventListeners("_child_btn_link", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        SetEventListeners("_child_btn_totop", {"mouseEnter" : this.HandleOverChildBtn,"mouseLeave" : this.HandleOutChildBtn,"mouseLeftButtonUp" : this.HandleReleaseGnaviBtnChild},this);
        //SetEventListeners("_btn_apply_child", {"mouseEnter" : this.HandleOverBtn,"mouseLeave" : this.HandleOutBtn,"mouseLeftButtonUp" : this.HandleReleaseApplyBtn},this);
        
        for(var i = 1; i<= 6; i++){
            SetEventListener("_btn_sub_about"+i, "mouseLeftButtonUp",this.HandleReleaseDetailAboutBtn,this);
        }
        
        this.linkAry_conference = [0,["conference/keynote_p.aspx",3],["conference/j_session_p.aspx",3],["conference/sessionlist_p.aspx#p03",2]];
        for(var i = 1; i< this.linkAry_conference.length; i++){
            SetEventListener("_btn_child_contents_conference" + i, "mouseLeftButtonUp",this.HandleReleaseChildContentsBtn_conference,this);
        }
        
        this.linkAry_innovation = [0,"garage/garage_p.aspx#p03","garage/garage_p.aspx","garage/garage_p.aspx#p01","garage/garage_p.aspx#p04","garage/garage_p.aspx#p02"];
        for(var i = 1; i< this.linkAry_innovation.length; i++){
            SetEventListener("_btn_child_contents_innovation"+i, "mouseLeftButtonUp",this.HandleReleaseChildContentsBtn_innovation,this);
        }
            
        this.linkAry_fun        = [0,["http://nextweb.spaces.live.com/",1],["funremix/award_p.aspx",3],["funremix/remixing_p.aspx",2],["funremix/accessories_p.aspx",3],["funremix/toukousakuhin_p.aspx",3]];
        for(var i = 1; i< this.linkAry_fun.length; i++){
            SetEventListener("_btn_child_contents_fun"+i, "mouseLeftButtonUp",this.HandleReleaseChildContentsBtn_fun,this);
        }
        
        this.linkAry_information = [0,["conference/sessionlist_p.aspx",1],["contact.aspx",1],["funremix/toukousakuhin_p.aspx",3],["funremix/accessories_p.aspx",3]];
        for(var i = 1; i< this.linkAry_information.length; i++){
            SetEventListener("_btn_information"+i, "mouseLeftButtonUp",this.HandleReleaseContentsBtn_information,this);
        }
        
        this.linkAry_partners   = [0,"http://www.2ndfactory.com/","http://www.nri-net.com/","http://www.est.co.jp/index.html","http://www.metaweb.co.jp/","http://www.voix.co.jp/","http://jp.infragistics.com/","http://www.gmo-hs.com/jpn/index.html","http://www.dstorm.co.jp","http://www.azest.co.jp","http://www.oii.co.jp"];
        for(var i = 1; i< this.linkAry_partners.length; i++){
            SetEventListeners("_btn_child_contents_partners"+i, {"mouseEnter" : this.HandleOverChildContentsBtn,"mouseLeave" : this.HandleOutChildContentsBtn,"mouseLeftButtonUp" : this.HandleReleaseChildContentsBtn_partners},this);
        }
            
        this.linkAry_link = [0,"http://www.microsoft.com/japan/msdn/nextweb/","http://silverlight.net/","/japan/msdn/nextweb/remix06/","http://www.microsoft.com/japan/windows/marketplace/webshowcase/","http://www.microsoft.com/japan/products/expression/default.mspx","http://gallery.live.com/","http://www.microsoft.com/japan/silverlight/"];
        for(var i = 1; i< this.linkAry_link.length; i++){
            SetEventListeners("_btn_child_contents_link"+i, {"mouseEnter" : this.HandleOverChildContentsBtn,"mouseLeave" : this.HandleOutChildContentsBtn,"mouseLeftButtonUp" : this.HandleReleaseChildContentsBtn_link},this);
        }
        
        this.linkAry_footer     = [0,"http://www.microsoft.com/japan/misc/cpyright.aspx","http://www.microsoft.com/japan/privacy/default.mspx","/japan/msdn/nextweb/remix07/contact.aspx"];
        for(var i = 1; i< this.linkAry_footer.length; i++){
            SetEventListener("_btn_footer"+ i, "mouseLeftButtonUp",this.HandleReleaseFooterBtn,this);
            SetEventListener("_btn_footer"+ i +"_child", "mouseLeftButtonUp",this.HandleReleaseFooterBtn,this);
        }
    }
}

function OpenWindow(url,type){
    var width;
    switch(type){
        case 1:
            width = 960;
            break;
        case 2:
            width = 730;
            break;
        case 3:
            width = 570;
            break;
    }
    var win = window.open(url,"windowName"+type, 'width='+width+', height=550, menubar=yes, toolbar=yes, scrollbars=yes, location=yes, resizable=yes, status = yes');
    win.focus();
}
function SetVisibility(target,flg){
    if(flg){
        target.Visibility = "Visible"; 
    }else{
        target.Visibility = "Collapsed";
    }
}
function BeginStoryboard(storyboard){
    sender.findName(storyboard).begin();
}
function StopStoryboard(storyboard){
    sender.findName(storyboard).stop();
}

