
/************************************************************
	Title: 	Vacation Survival Guide Master JS
	Author:	AgencyNet
	Date: 	Aug 08
	Desc:		Defines Javascript Code for Entire Site.
	
	Reference:
		darkBlue(fonts) : #5a849d
		lightBlue : #bbdcef
************************************************************/

var VacationSurvivalGuide = { 
	options: {
		
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	initialize: function(){
		//alert('hello');
		//var smartSearch = new SmartSearch('smartSearch', {borderColor:'00FF00'});
		//var formEffects = new FormEffects('.smartSearch', {borderColor:'00FF00'});
		
		//Code for all pages
		//var searchForm = new FormEffects('.smartSearch');
		
		//rather than having a look up for each if statement...do it once (body tag id)..then compare that variable
		//TO DO
//		var bodyID = 

		//smartSearch
		if($('smartSearch') && !($('memberDetail'))){
			var temp = new FormEffects('smartSearch');  
		}
		
		//Login Page Code
		if($('loginPage')){
			this.loginPage();
		}	//END OF LOGIN PAGE	
		
		//Dashboard Code
		if($('dashboard')){
			this.dashboardPage();
		}
		
		//Article Detail Code
		if($('articleDetail')){
			this.articleDetailPage();
		}	
		
		//memberDetail Code
		if($('memberDetail')){
			this.memberDetailPage();
		}
		
		//signinPage Code
		if($('signinPage')){
			this.signinPage();	
		}
		
		//Either of the 3 phases page
		if($('planAhead') || $('theVacation') || $('gettingBack')){
			this.doubleRollovers();
			this.translateUserNames();
		}
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	signinPage: function(){
		//Slider for picking family size
		var familyNumDisplay = $('numDisplay');
			var plus = '';
			this.ratingSys = new Slider($('sliderBarWidth'), $('knob'), {
				steps: 8,
				onChange: function(step){
					this.options.ratingValue = step;
					if(step == 8)
						plus = '+';
					else
						plus = "";
					familyNumDisplay.setHTML(step + plus);
				}.bind(this)
			}).set(2);
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	memberDetailPage: function(){	
		this.translateCommenterNames();
		//need to add tooltip functionality :: Tool Tip functionality removed b/crating uses
/*		var toolTips = new Tips($$('.toolTip'), {
				className: 'web2',
				offsets: {'x': -5, 'y': -35},
				initialize:function(){
					this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 300, wait: false}).set(0);
				},
				onShow: function(toolTip) {
					this.fx.start(1);
				},
				onHide: function(toolTip) {
					this.fx.start(0);
				}
		}); */
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	doubleRollovers: function() {
		//gets all entries, and adds a rollover effect to each title
		var entries = $$('.entry');
		entries.each(function(el, i){
			var headerEle = el.getFirst();
			var bottomEle = el.getLast();
			headerEle.addEvent('mouseover', function(){
				bottomEle.addClass('hover');																				 
			}.bind(this));
			headerEle.addEvent('mouseout', function(){
				bottomEle.removeClass('hover');																				 
			}.bind(this));									
		}.bind(this));
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	articleDetailPage: function(){
		//add tooltips to page
		var toolTips = new Tips($$('.toolTip'), {
				className: 'web2',
				offsets: {'x': -5, 'y': -35},
				initialize:function(){
					this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 300, wait: false}).set(0);
				},
				onShow: function(toolTip) {
					this.fx.start(1);
				},
				onHide: function(toolTip) {
					this.fx.start(0);
				}
		});
		//add Send to Friends Functionality is now in a seperate js file
		//this.send2Friend();
		this.translateCommenterNames();
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	dashboardPage: function(){
		//Redirect code to make sure user is logged in.
//		if (!( commenter_name && ( !commenter_id || commenter_blog_ids.indexOf("'1'") > -1)))
//			window.location = "/mt/login.cgi?__mode=login&blog_id=1&static=/dashboard"
			
		//check for submission sucess
		this.checkForSubmissionSuccess();
		
		var loginForgotPswd = new DashBoardTabs();
	
		var helpMeSubmit = $('submitDashHelp');
		var helpMeSubmitInfo = $('submitHelp');
		var helpMeFavs = $('myFavsDashHelp');
		var helpMeFavsInfo = $('myFavsHelp');
		
		helpMeSubmit.addEvent('mouseover', function(){
			helpMeSubmitInfo.setStyle('display','block');
		}.bind(this));
		helpMeSubmit.addEvent('mouseout', function(){
			helpMeSubmitInfo.setStyle('display','none');
		}.bind(this));
		
		helpMeFavs.addEvent('mouseover', function(){ 
			helpMeFavsInfo.setStyle('display','block');
		}.bind(this));
		helpMeFavs.addEvent('mouseout', function(){ 
			helpMeFavsInfo.setStyle('display','none');
		}.bind(this));
		
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	checkForSubmissionSuccess: function(){	
		var tempUrl = window.location.search.substring(1);
		if(tempUrl == "s=y") {
			var submitSuccess = $('submitSuccess');
			var closeSubmitSuccess = $('closeSubmitSuccess');
			
			//show success
			submitSuccess.setStyle('display','block');
			
			closeSubmitSuccess.addEvent('click', function(){
				submitSuccess.setStyle('display','none');																							
			});
		}
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	loginPage: function(){
		//hide forgotPswd form
		var loginForgotPswd = new CollapsibleDiv('collapsibleForgotPassword', 'forgotPswdBut');
		
		//decide if there is an anchor in url
		var locationObj = window.location;         //gets URL
		var locationObj = locationObj.toString();  //sets URL to string
		
		// check if strings are anywhere in the URL
		if(locationObj.test("registerForm")) {
			$('registerButton').setStyle('display','none');
		}	else {
			var registerForm = new CollapsibleDiv('createAccount','registerButton');
		}
		
		//var yourProfileToolTips = new ToolTip('');
		
		//Slider for picking family size
		var familyNumDisplay = $('numDisplay');
		var plus = '';
		this.ratingSys = new Slider($('sliderBarWidth'), $('knob'), {
			steps: 8,
			onChange: function(step){
				this.options.ratingValue = step;
				if(step == 8)
					plus = '+';
				else
					plus = "";
				familyNumDisplay.setHTML(step + plus);
			}.bind(this)
		}).set(2);
	}, 
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	translateUserNames: function(){
		if($$(".memberSubmittedTip .memberInfo")){
			var allMemberTips = $$(".memberSubmittedTip .memberInfo")
			
			allMemberTips.each(function(el,i){ 
				var initialName = unescape(el.innerHTML);
				var userProfileValues = initialName.split('|');
				
				var userNameAndLocation = userProfileValues[0];
				if(userProfileValues[3] != null){
					userNameAndLocation += " | " + userProfileValues[3];
				}
				el.setHTML(userNameAndLocation);
			}.bind(this));
		}
	},
//~~~~~~~~~~~~~~~~~~~~~~>>>>>><<<<<<~~~~~~~~~~~~~~~~~~~~~~//
	translateCommenterNames: function(){
		if($$(".commentInfo .commenter")){
			var allMemberTips = $$(".commentInfo .commenter")
			
			allMemberTips.each(function(el,i){ 
				var initialName = unescape(el.innerHTML);
				var userProfileValues = initialName.split('|');
				
				var userNameAndLocation = userProfileValues[0];
				if(userProfileValues[3] != null){
					userNameAndLocation += " | " + userProfileValues[3];
				}
				el.innerHTML = userNameAndLocation;
			}.bind(this));
		}
	}
};

window.addEvent('load', VacationSurvivalGuide.initialize.bind(VacationSurvivalGuide));
//window.onDomReady(VacationSurvivalGuide.initialize.bind(VacationSurvivalGuide));