var rel_path;
var page;

function nav_init(p,rp) {
	rel_path = rp;
	page = p;
	if(p!='home'){embed_swf('home',"70","30")};
	if(p!='about-us'){embed_swf('about-us',"95","30")};
	if(p!='services'){embed_swf('services',"92","30");}
	if(p!='portfolio'){embed_swf('portfolio',"106","30")};
	if(p!='contact'){embed_swf('contact',"86","30")};
}
function contact_init() {
  	$$('.info').invoke('update','info@');
  	$$('.winterson-design').invoke('update',"wintersondesign.com");
}
function validate_form() {
	var alerts = [];
	if($F('name')==''){alerts.push('Please enter your name.');}
	if($F('email')=='' && $F('phone')==''){alerts.push('Please enter your email address.');}
	if(alerts.length == 0){return true};
	$('alert').update(alerts.join('<br/>'));
	return false;
}


function embed_swf(swf,w,h) {
	var flashvars_main = {};
	var params_main = {
	  wmode: "transparent",
	  menu: "false",
	  bgcolor: "#000000",
	  allowscriptaccess: "always"
	};
	var attributes_main = {};
	swfobject.embedSWF('http://wintersondesign.com.s3.amazonaws.com/flash/'+swf+'.swf', swf, w, h, "8","", flashvars_main, params_main, attributes_main);
}

//Load:  all headlines white, all explanations closed, body at normal state
//Roll over headline:  
	//all explanations closed:  headline turns red, all explanations remain closed, body at headline's state
	//open_explanation explanation open, rolling over other headline: open_explanation headline remains red,  other headline turns red, open_explanation explanation remains open, body stays at open_explanation
//Roll off headline:  
	//all explanations closed:  headline turns white, all explanations remain closed, body at normal state
	//open_explanation explanation open, rolling off other headline: open_explanation headline remains red, other headline turns white, open_explanation explanation remains open, body stays at open_explanation
//Click on headline:
	//item closed:  headline remains red, all other headlines turn white, explanation opens, all other explanations close, body at item's state
	//item open: headline remains red, open_explanation closes, body at normal state
//Close explanation manually:
	//headline turns white, open_explanation closes, body at normal state

//Load:  all headlines unselected, open_explanation = '', pieces additional classname = ''
//Roll over headline:  
	//all explanations closed:  this headline gets selected, pieces add classname this item
	//open_explanation explanation open, rolling over other headline: this headline gets selected
//Roll off headline:  
	//all explanations closed:  this headline removes selected, pieces remove classname for this item
	//open_explanation explanation open, rolling off this headline: <nothing>
	//open_explanation explanation open, rolling off other headline: other headline removes selected, 
//Click on headline:
	//this item closed: (2)headlines remove selected, this headline gets selected, close any open explantions, pieces additional classname = '', open_explanation = this item, explanation opens, pieces additional classname = item
	//this item open: (1)this headline remove selected, open_explanation closes, pieces additional classname = ''
	//other item open: do 1 then 2
//Close explanation manually:
	//all headlines remove selected, open_explanation = '', pieces additional classname = ''
	
var active_headlines;
var open_explanation='';

function active_headline_init() {
	active_headlines = $$('.active-headline');
	active_headlines.invoke('observe','mouseover',doMouseOverHeadline);
	active_headlines.invoke('observe','mouseout',doMouseOutHeadline);
	active_headlines.invoke('observe','click',doClickHeadline);
	$$('.explanation').invoke('hide');
}

function doMouseOverHeadline(){
	this_id = this.id;
	if(!this.hasClassName('special')){$$('#'+this_id+' .carrot')[0].setStyle({backgroundPosition: '0px 10px'})};
	
}

function doMouseOutHeadline(){
	this_id = this.id;
	if(open_explanation==''){
		if(!$(this_id).hasClassName('special')){$$('#'+this_id+' .carrot')[0].setStyle({backgroundPosition: '0px 0px'})};
	}else{
		if(open_explanation!=this_id){
			if(!this.hasClassName('special')){$$('#'+this_id+' .carrot')[0].setStyle({backgroundPosition: '0px 0px'})};
		}
	}
	
}

function doClickHeadline(){
	headline_id = this.id;
	if(open_explanation==headline_id){
		//close this explanation
		do_close_explanation(true)		
	}else{
		//close any other explanations, open this explanation
		if(open_explanation!=''){do_close_explanation(true)};	
		do_open_explanation(headline_id)
	}
}

function do_close_explanation(manual_close) {
	if(manual_close){
		Effect.BlindUp($(open_explanation).next());
	}
	active_headlines.invoke('removeClassName','selected');
	if(!$(open_explanation).hasClassName('special')){$$('#'+open_explanation+' .carrot')[0].setStyle({backgroundPosition: '0px -3px'})};
	open_explanation = '';
}

function do_open_explanation(headline_id) {
	open_explanation = headline_id;
	Effect.BlindDown($(open_explanation).next());
	$(headline_id).addClassName('selected');
	if(!$(open_explanation).hasClassName('special')){$$('#'+open_explanation+' .carrot')[0].setStyle({backgroundPosition: '0px 11px'})};
	
}
