﻿//SeasonCardsBuilder.js
//This is the main reference for all branch scripts.

if (!window.SeasonCardsBuilder)
	window.SeasonCardsBuilder = {};

SeasonCardsBuilder.App = function() 
{
    
}

SeasonCardsBuilder.App.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		
		
	    //////////////////////////////////////////////////////////////////////////////   
	    //Variables///////////////////////////////////////////////////////////////////
	    //////////////////////////////////////////////////////////////////////////////
		this.control = control;
		this.baseURL = "http://www.microsoft.com/silverlight/sharethelove/";
		this._enable = false;
		this.cardItems = {};
		this.musicArray = new Array(
			Array("http://download.microsoft.com/download/6/E/F/6EF86C91-541A-4C93-8896-A32BEB09D4C2/Accordion-Concertina-Hornpipe.wma", "assets/images/acordian.png"),
			Array("http://download.microsoft.com/download/6/E/F/6EF86C91-541A-4C93-8896-A32BEB09D4C2/band-Apple-spoof.wma", "assets/images/piano.png"),
			Array("http://download.microsoft.com/download/6/E/F/6EF86C91-541A-4C93-8896-A32BEB09D4C2/Guitar-Shine.wma", "assets/images/guitar.png"),
			Array("http://download.microsoft.com/download/6/E/F/6EF86C91-541A-4C93-8896-A32BEB09D4C2/Piano-Love-Ballad.wma", "assets/images/piano.png"),
			Array("http://download.microsoft.com/download/6/E/F/6EF86C91-541A-4C93-8896-A32BEB09D4C2/Piano-Loving-Hearts.wma", "assets/images/piano.png"),
			Array("http://download.microsoft.com/download/6/E/F/6EF86C91-541A-4C93-8896-A32BEB09D4C2/Violin-Mozartian-Trio.wma", "assets/images/violin.png"),
			Array("http://download.microsoft.com/download/6/E/F/6EF86C91-541A-4C93-8896-A32BEB09D4C2/Violin-Palm-Court.wma", "assets/images/violin.png")
		);
		this.pastCallback;
		this.cardLocked = false;
		this.storyboards = {};
		this.cardItems.selectedPhotoArray = new Array();
		this.dialogueArray = new Array("dialogue_photos","dialogue_flickr_username","dialogue_spaces","boxPicSelector","dialogue_message","dialogue_music", "dialogue_email");
		this.musicPlayer = this.control.content.findname("me_musicPlayer");
		
		
	  	 
	 //UPDATE the Card based on the url structure if there is one.
	 //Url parsing is done in parseURL.js - URLarray is returned
	   var URLarray = parseURL();
		if(URLarray){ 
				if(URLarray[0]){
					this.cardItems.selectedPhotoArray.push(URLarray[0]);
				} else {
					this.cardItems.selectedPhotoArray[0] = "assets/images/MSCMem07_yulia.jpg";
				}
		
				if(URLarray[1]){
					this.cardItems.message = URLarray[1];
					document.getElementById("card_message").value = URLarray[1];
				} else {
					this.cardItems.message = "Build your own Valentine's card.  Click on one of the three buttons below to begin.  Finish all three to send your Valentine's email.";
					document.getElementById("card_message").value =this.cardItems.message;
				}
				if(URLarray[2]){
					this.cardItems.musicItem = URLarray[2]; 
					this.musicPlayer.source = this.musicArray[URLarray[2]][0];
					this.musicPlayer.play();//	 alert(URLarray[0]);	
				} else {
					this.cardItems.musicItem = 4;
					this.musicPlayer.source = this.musicArray[this.cardItems.musicItem][0];
					this.musicPlayer.play();//	 alert(URLarray[0]);	
				}
		}
		else {
			this.cardItems.selectedPhotoArray[0] = "assets/images/MSCMem07_yulia.jpg";
			this.cardItems.message = "Build your own Valentine's card.  Click on one of the three buttons below to begin.  Finish all three to send your Valentine's email.";
			document.getElementById("card_message").value =this.cardItems.message;
			this.cardItems.musicItem = 4;
			this.musicPlayer.source = this.musicArray[this.cardItems.musicItem][0];
			this.musicPlayer.play();//	 alert(URLarray[0]);	
		}
			

		//////////////////////////////////////////////////////////////////////////////
		//Slider Controls/////////////////////////////////////////////////////////////
		//////////////////////////////////////////////////////////////////////////////
		this.photoSlider = new slider(this.control, "sliderButtonTop1", "sliderButtonBottom1", "sliderHandle1", "sliderTrack1", "dialogue_photos_selectphotoHolder", "slider1", 315, 406, 0, 25);
		
		//////////////////////////////////////////////////////////////////////////////
		//CanvasManagers: new CanvasManagerLite("SL id", "Canvas")////////////////////
		//////////////////////////////////////////////////////////////////////////////
		
		//this.templateSelectionManager = new CanvasManager("SilverlightControl", "dialogue_photos_selecttemplate");
		this.cardManager = new CanvasManager("SilverlightControl", "cardHolder");
		this.photoManager = new CanvasManager("SilverlightControl", "dialogue_photos_selectphotoHolder");
		this.musicManager = new CanvasManager("SilverlightControl", "hldr_musicSelect");
    
	
	 	
		//////////////////////////////////////////////////////////////////////////////
		//Other Controls//////////////////////////////////////////////////////////////
		//////////////////////////////////////////////////////////////////////////////
		//this.templateControl = new templateControl(this.control);
		this.sourceControl = new sourceControl(this.control);
		this.flickrUsernameControl = new flickrUsernameControl(this.control);
		this.emailControl = new emailControl(this.control);
		this.photosControl = new photosControl(this.control);
		this.messageControl = new messageControl(this.control);
		this.musicControl = new musicControl(this.control);
		//this.cardControl = new cardControl(this.control);
		

	   //////////////////////////////////////////////////////////////////////////////
		//Load Greeting Card Template////////////////////////////////////////////////
		//////////////////////////////////////////////////////////////////////////////
	    this.cardID = this.cardManager.loadXaml("cards/VC.xaml", (1), {Left: 0, Top: 0, File: {init: "cardControl", params: this.cardItems.selectedPhotoArray[0]}});
	  	
	
	   
	   this.btn_music = this.control.content.findName("btn_music");
    	this.btn_email = this.control.content.findName("btn_email");
    	this.btn_message = this.control.content.findName("btn_message");
    	this.btn_image = this.control.content.findName("btn_image");

    	this.storyboards.btn_image_over = this.control.content.findName("btn_image_over");
		this.storyboards.btn_image_out = this.control.content.findName("btn_image_out");
    	this.storyboards.btn_message_over = this.control.content.findName("btn_message_over");
		this.storyboards.btn_message_out = this.control.content.findName("btn_message_out");
		this.storyboards.btn_music_over = this.control.content.findName("btn_music_over");
		this.storyboards.btn_music_out = this.control.content.findName("btn_music_out");
		this.storyboards.btn_email_over = this.control.content.findName("btn_email_over");
		this.storyboards.btn_email_out = this.control.content.findName("btn_email_out");
		
		this.storyboards.source_in = this.control.content.findName("source_in");
		this.storyboards.message_in = this.control.content.findName("message_in");
		this.storyboards.music_in = this.control.content.findName("music_in");
		this.storyboards.flickr_photos_in = this.control.content.findName("flickr_photos_in");
		this.storyboards.username_in = this.control.content.findName("username_in");
		this.storyboards.spaces_in = this.control.content.findName("spaces_in");
		this.storyboards.email_in = this.control.content.findName("email_in");
	
	
    	//Set Cursor
    	this.btn_music.cursor = "Hand";
		this.btn_email.cursor = "Hand";
		this.btn_message.cursor = "Hand";
		this.btn_image.cursor = "Hand";
		
    	this.btn_music.addEventListener("mouseEnter", Silverlight.createDelegate(this, this.btn_music_enter));
		this.btn_email.addEventListener("mouseEnter", Silverlight.createDelegate(this, this.btn_email_enter));
		this.btn_message.addEventListener("mouseEnter", Silverlight.createDelegate(this, this.btn_message_enter));	
		this.btn_image.addEventListener("mouseEnter", Silverlight.createDelegate(this, this.btn_image_enter));	
		
		this.btn_music.addEventListener("mouseLeave", Silverlight.createDelegate(this, this.btn_music_leave));
		this.btn_email.addEventListener("mouseLeave", Silverlight.createDelegate(this, this.btn_email_leave));
		this.btn_message.addEventListener("mouseLeave", Silverlight.createDelegate(this, this.btn_message_leave));	
		this.btn_image.addEventListener("mouseLeave", Silverlight.createDelegate(this, this.btn_image_leave));
		
	
    	this.btn_music.addEventListener("mouseLeftButtonDown", Silverlight.createDelegate(this, this.btn_music_press));
		this.btn_email.addEventListener("mouseLeftButtonDown", Silverlight.createDelegate(this, this.btn_email_press));
		this.btn_message.addEventListener("mouseLeftButtonDown", Silverlight.createDelegate(this, this.btn_message_press));	
		this.btn_image.addEventListener("mouseLeftButtonDown", Silverlight.createDelegate(this, this.btn_image_press));	
	   },
	
	
	btn_music_enter: function(){
		this.storyboards.btn_music_over.begin();
	},
	btn_email_enter: function(){
		this.storyboards.btn_email_over.begin();
	},
	btn_message_enter: function(){
		this.storyboards.btn_message_over.begin();
	},
	btn_image_enter: function(){
		this.storyboards.btn_image_over.begin();
	},
	
	btn_music_leave: function(){
		this.storyboards.btn_music_out.begin();
	},
	btn_email_leave: function(){
		this.storyboards.btn_email_out.begin();
	},
	btn_message_leave: function(){
		this.storyboards.btn_message_out.begin();
	},
	btn_image_leave: function(){
		this.storyboards.btn_image_out.begin();
	},
	
	
	
	btn_message_in: function(){
		openMessageInput();
	},
	
	btn_music_press: function(){
			this.storyboards.music_in.begin();
			this.changeDialogue("dialogue_music", 0);
			
	},
	btn_email_press: function(){
		this.changeDialogue("", 0);
			this.storyboards.email_in.begin();
			document.getElementById("email_input").style.visibility = "visible";
			this.changeDialogue("dialogue_email", 1);
	},
	btn_message_press: function(){
				this.changeDialogue("", 0);
			this.storyboards.message_in.begin();
			this.changeDialogue("dialogue_message", 1);
			document.getElementById("message_input").style.visibility = "visible";
			document.getElementById("message_input").value = document.getElementById("card_message").value;
	},
	btn_image_press: function(){
			this.storyboards.source_in.begin();
			this.changeDialogue("boxPicSelector", 0);
	},
	
	
	//Change Dialogue removes all dialogues (HTML & Silverlight) when a single dialogue is opened.
	changeDialogue: function(dialogue, html){
		//There are mutliple dialogue
		if(dialogue == "" && html == 0){document.getElementById("card_message").style.visibility = "visible"; this.cardLocked = false; } else { document.getElementById("card_message").style.visibility = "hidden"; this.cardLocked = true;}
		//There are a couple html dialogue
		var htmlDialogueArray = new Array("flickr_username_input","message_input", "email_input", "displaySpaces");
		//alert("dialogue hit");
		for (i=0; i < this.dialogueArray.length; i++){
			if(dialogue != this.dialogueArray[i]){
					this.control.content.findName(this.dialogueArray[i]).opacity = 0;
					this.control.content.findName(this.dialogueArray[i]).visibility = "collapsed";
			} else {
				this.control.content.findName(this.dialogueArray[i]).visibility = "visible";
			}
		}
		if(!html){
			for (h=0; h < htmlDialogueArray.length; h++){
				document.getElementById(htmlDialogueArray[h]).style.visibility = "hidden";
			}
			document.getElementById("displaySpaces").style.top = '-500px';
			document.getElementById("sControl").style.width = '1px';
		}
	
	
	}
	
	

	

}//End Class



