// JavaScript Document


App.tabs = {};

window.addEvent("unload", function(event){
	
});

window.addEvent("domready", function(){
	var tempEl = null, scaleTabIndex = null;
	
	//==== modal
	App.modal = new modalWindow("global_container", { classPrefix: "modal_" });
	
	//the main sliding panel
	App.tabs.mainSlider = new slidingPanel({
		container: "homeSlider",
		tabs: "Tab",
		selected: "selectedTab",
		first: "firstTab",
		last: "lastTab",
		disabled: "disabledTab",
		panels: "panel",
		defaultTab: 0,
		hideBy: "visibility",
		width: 750,	
		height: 400,	
		direction: "horizontal",
		duration: 1200,
		onChange: function(index){
			if (index == 1){
				App.tabs.scaleSlider.select(scaleTabIndex);
			} else {
				App.tabs.scaleSlider.hideAll();
			}
		}
	});
	
	
	//the scale sliding panel
	App.tabs.scaleSlider = new slidingPanel({
		container: "scaleSlider",
		tabs: "Tab",
		selected: "selectedTab",
		first: "firstTab",
		last: "lastTab",
		disabled: "disabledTab",
		panels: "panel",
		defaultTab: null,
		hideBy: "visibility",
		width: 750,	
		height: 400,	
		panelWidth: 505,
		direction: "vertical",
		duration: 1200,
		onChange: function(index){
			//if (App.tabs.scaleSlider.panels[index].getElement(".the_scale_container").getStyle("left").toInt() == 0){
			App.contentScale_fx.start("left", 600);
			App.qualityScale_fx.start("left", 600);
			App.usabilityScale_fx.start("left", 600);
			//}
			
			if (index == 0){
				if (App.tabs.scaleSlider.panels[index].getElement(".C_question_toggle").offsetHeight == 0){
					App.content_togglers.display(0);
				}
			} else if (index == 1){
				if (App.tabs.scaleSlider.panels[index].getElement(".Q_question_toggle").offsetHeight == 0){
					App.quality_togglers.display(0);
				}
			} else if (index == 2){
				if (App.tabs.scaleSlider.panels[index].getElement(".U_question_toggle").offsetHeight == 0){
					App.usability_togglers.display(0);
				}
			} 
		}
	});
	
	//scale buttons on the homepage
	var home_buttons = $("home_leftColumn").getElements(".home_buttons_v2");
	home_buttons.addEvent("click", function(event){
		event.stop();
		if (this == home_buttons[0]){ scaleTabIndex = 0; } 
		else if (this == home_buttons[1]){ scaleTabIndex = 1; } 
		else if (this == home_buttons[2]){ scaleTabIndex = 2; }
		App.tabs.mainSlider.select(1);
		App.tabs.scaleSlider.showAll();
		//App.tabs.scaleSlider.select(0);
	});
	//home_buttons = null;
	
	//disclaimer link
	tempEl = $("link_disclaimer");
	tempEl.addEvent("click", function(event){
		event.stop();
		App.modal.launch({ width: 450, height: 200, title: "Disclaimer", html: "The Quality Assessment Toolbox website is designed for educational purposes only and is not intended to serve as medical advice.  Genetic Alliance disclaims responsibility for any injury and/or damage to persons or property as a result of any actual or alleged libelous statements, infringement of intellectual property or other proprietary or privacy rights, or from use or operation of any ideas, instructions, procedures, products, or methods contained in the material herein.", onLoad: function(){} });
	});
	tempEl = null;
	
	
		//about link
	tempEl = $("link_about");
	tempEl.addEvent("click", function(event){
		event.stop();
		App.modal.launch({ width: 500, height: 400, title: "About", iframe: true, url: "about.html", onLoad: function(){} });
	});
	tempEl = null;
	
	
	//go back to home
	tempEl = $("tab_home");
	tempEl.addEvent("click", function(event){
		event.stop();
		App.tabs.mainSlider.select(0);
	});
	tempEl = null;
	
	
	//questions toggler
	App.content_togglers = new Accordion($$('.C_question_toggler'), $$('.C_question_toggle'), { show : -1, alwaysHide: true, multiopen: false, opacity: false, duration: 500 });
	App.quality_togglers = new Accordion($$('.Q_question_toggler'), $$('.Q_question_toggle'), { show : -1, alwaysHide: true, multiopen: false, opacity: false, duration: 500 });
	App.usability_togglers = new Accordion($$('.U_question_toggler'), $$('.U_question_toggle'), { show : -1, alwaysHide: true, multiopen: false, opacity: false, duration: 500 });
	
	//scale toggler
	App.C_content_togglers = new Accordion($$('.C_scale_toggler'), $$('.C_scale_toggle'), { show : 0, alwaysHide: true, multiopen: false, opacity: false, duration: 500 });
	//App.Q_content_togglers = new Accordion($$('.Q_scale_toggler'), $$('.Q_scale_toggle'), { show : -1, alwaysHide: true, multiopen: false, opacity: false, duration: 200 });
	App.U_content_togglers = new Accordion($$('.U_scale_toggler'), $$('.U_scale_toggle'), { show : 0, alwaysHide: true, multiopen: false, opacity: false, duration: 500 });
	
	//Content Scale Details
	App.contentScale_fx = new Fx.Tween($("the_content_scale"), {duration: 500, transition: Fx.Transitions.Expo.easeOut, link: 'cancel', onStart: function(){}, 																														  		onComplete:function(){
			var tempEl_2 = $("the_content_scale");
			if (tempEl_2.getStyle("visibility") == "visible" && tempEl_2.getStyle("left").toInt() > 0)	{
				tempEl_2.invisible();
			} 
			tempEl_2 = null;
		}
	});
	tempEl = $("panel_content_scale").getElements(".content_scale_launcher");
	tempEl.addEvent("click", function(event){
		event.stop();
		$("the_content_scale").visible();
		App.contentScale_fx.start("left", 0)
	});
	tempEl = null;
	tempEl = $("close_theContentScale");
	/*tempEl.addEvent("click", function(event){
		event.stop();
		App.contentScale_fx.start("left", 600);
	});*/
	tempEl = null;
	
	//Quality Scale Details
	App.qualityScale_fx = new Fx.Tween($("the_quality_scale"), {duration: 500, transition: Fx.Transitions.Expo.easeOut, link: 'cancel', onStart: function(){}, 																														  		onComplete:function(){
			var tempEl_2 = $("the_quality_scale");
			if (tempEl_2.getStyle("visibility") == "visible" && tempEl_2.getStyle("left").toInt() > 0)	{
				tempEl_2.invisible();
			}
			tempEl_2 = null;
		}
	});
	tempEl = $("launch_quality_scale");
	/*tempEl.addEvent("click", function(event){
		event.stop();
		$("the_quality_scale").visible();
		App.qualityScale_fx.start("left", 0)
	});
	tempEl = null;
	tempEl = $("close_theQualityScale");
	tempEl.addEvent("click", function(event){
		event.stop();
		App.qualityScale_fx.start("left", 600);
	});
	tempEl = null;*/
	
	//Quality Scale Details
	App.usabilityScale_fx = new Fx.Tween($("the_usability_scale"), {duration: 500, transition: Fx.Transitions.Expo.easeOut, link: 'cancel', onStart: function(){}, 																														  		onComplete:function(){
			var tempEl_2 = $("the_usability_scale");
			if (tempEl_2.getStyle("visibility") == "visible" && tempEl_2.getStyle("left").toInt() > 0)	{
				tempEl_2.invisible();
			} 
			tempEl_2 = null;
		}
	});
	tempEl = $("launch_usability_scale");
	/*tempEl.addEvent("click", function(event){
		event.stop();
		$("the_usability_scale").visible();
		App.usabilityScale_fx.start("left", 0)
	});
	tempEl = null;
	tempEl = $("close_theUsabilityScale");
	tempEl.addEvent("click", function(event){
		event.stop();
		App.usabilityScale_fx.start("left", 600);
	});
	tempEl = null;*/
	
	
	//============= opening the external linkout file ===========
	tempEl = $("global_body").getElements(".the_scale_container a.linkout");
	tempEl.addEvent("click", function(event){
		event.stop();
		App.modal.launch({ width: 600, height: 400, title: this.get("html"), iframe: true, url: this.href });
	});
	
});
		
		

		