/*
	function imageHeader(selector,font_file,font_size,font_color, background_color, hover_color,hover_background,wordwrap){
		this.selector = selector;
		this.font_file = font_file;
		this.font_size = font_size;
		this.font_color = font_color;
		this.background_color = background_color;
		this.hover_color = hover_color;
		this.hover_background = hover_background;
		this.wordwrap = wordwrap;
	}
	var imageHeaders = [
		//new imageHeader("#navPrimary > li > a","Swiss721BT_Med","11.5","9F7A26","FDFBC8","5B553B","F1E7B2",false),
		new imageHeader("#footer h3","Swiss721BT_Med","7","333333","666666","","",false)

		]

	var testURL = "images/test.png" ;
	var doNotPrintImages = false;
	var printerCSS = "css/replacement-print.css";
	var hideFlicker = false;// for this to work, the CSS file below must trap all the styles defined in script above
	var hideFlickerCSS = "css/replacement-screen.css";
	var hideFlickerTimeout = 1000;

	*/

function initWorkDots(){
	//var workDots = cssQuery("#navigationWork li a");
	var workDots = $$('#navigationWork li a');
	workDots.each(
		function(element){
			element.addEvent("click", function(event){getWork(this.id.replace('item',''),this.title);});
			element.addEvent("mouseover", function(event){showWorkTitle('show',this.title,this.rel);});
			element.addEvent("mouseout", function(event){showWorkTitle('hide','','');});
			element.addEvent("click", function(element){this.addClass('current');});
		}
		);
}
function showWorkTitle(vis,title,rel){
	var cover = $('portfolioItemTitleCover');
	if(vis == 'show'){
		var titleText = '';
		for(i = 0; i < rel; i++) {
			titleText += '<span class="workSub">'+(i+1)+'</span>';
		}
		cover.innerHTML = title + titleText;
		cover.setStyle('display','block');
	}else{
		cover.setStyle('display','none');
	}
}
window.addEvent("domready", initWorkDots);
window.addEvent("domready", initHWslide);

function initHWslide(){
	
	try{clearInterval(hwslideinterval);} catch(e){null;}	
	var HWslides= $$('.HWslide'); // make HWslides an array of our slide img elemets
	if(HWslides.length > 0){ // if we have any
	var showSlide=$('HWslide0');
	var slideNum=0;

	hwslideinterval=setInterval(function(){
			if(showSlide!=null){
			//alert("Hiding"+showSlide.id);
			var myFadeOut = new Fx.Style(showSlide, 'opacity', {duration: 750, wait: false}).set(1);
			myFadeOut.start(0); // fade it out
			}
			nextSlide=(slideNum+1==3 ? 0 : slideNum+1); 
			showSlide=$('HWslide'+nextSlide);
			if(showSlide!=null){			
			//alert("Showing:"+showSlide.id);			
			var myFader = new Fx.Style(showSlide, 'opacity', {duration: 750, wait: false}).set(0);
			myFader.start(1);
			}
			slideNum=nextSlide;
		},5000);
	}
}
function initWorkSubs(){
	//var workSubs = cssQuery(".workSub");
	var workSubs = $$('.workSub');
	if(workSubs.length > 0){
	workSubs.each(
		function(element){
			//element.addEvent("click", function(event){getWork(this.id.replace('item',''),this.title);return false;});
			element.addEvent("click", function(event){carousel_6.showSlide(parseInt(this.innerHTML)-1);return false;});  
			element.addEvent("click", function(element){this.toggleClass('current');workSubsDeactivate(this.id);return false;});
		}
		);
	workSubs[0].addClass('current');
	$('portfolioItemTitleCover').setStyle('display','none');
	}
}
function workSubsDeactivate(activeID){
	//alert(activeID);
$$('.workSub').each(
	function(element)
	 {
		 if(element.id != ''+activeID){
			 element.removeClass('current');
		 }
	 }
	 );
}
var Json = {
	toString: function(obj){
		var string = [];
		switch ($type(obj)){
			case 'string':
				return '"'+obj.replace(new RegExp('(["\\\\])', 'g'), '\\$1')+'"';
			case 'array':
				obj.each(function(ar){
					string.push(Json.toString(ar));
				});
				return '['+string.join(',')+']';
			case 'object':
				for (var property in obj) string.push('"'+property+'":'+Json.toString(obj[property]));
				return '{'+string.join(',')+'}';
		}
		return String(obj);
	},

	evaluate: function(str){
		return eval('(' + str + ')');
	}

};
function getWork(id,title){
	$('container').addClass('processing');
	var jsonString = Json.toString({method: 'getArticle', params: id});
	new Ajax('./jsonservice2.php', {data: jsonString, onComplete: function(req){var article = Json.evaluate(req);loadWork(article);}}).request();
	//$('portfolioItemTitle').innerHTML = title;
	
}
var portfolioItemCurrent = "";
var carousel_6;
function loadWork(article){
	//alert(article.title);
	$('portfolioPanel').setHTML(article.subPanel);
	portfolioItemCurrent = article.title+article.subs;
	$('portfolioItemTitle').innerHTML = article.title+article.subs;
	
	var fadeOne = new Fx.Style('portfolioPanel', 'opacity', {duration: 750, wait: false}).set(0);
	fadeOne.start(0);
	fadeOne.start(1);
	swapSlide('portfolioPanel');
	carousel_6 = new SimpleSlideShow({
			  startIndex: 0,
			  slides: $$('.carousel_6_item'),
			//  currentIndexContainer: '', //an element or it's id
			//  maxContainer: '',
			  nextLink: 'carousel_6_next',
			  prevLink: 'carousel_6_previous',
			  currentSlideClass:'currentSlide',
			  wrap:false,
			  crossFadeOptions: {
				duration: 250
			}
			});
	//alert('item'+article.item);
	$$('.current').each(
	function(element)
	 {
		 if(element.id != 'item'+article.id){
			 element.removeClass('current');
		 }
	 }
	 );
	
	initWorkSubs();
	buildSlideShow();
	$('container').removeClass('processing');
	//});
	initHWslide();
}
function showHideFlash(vis){
	embeds = document.getElementsByTagName('embed');
	objects = document.getElementsByTagName('object');
	
	if(vis == "hide"){
		for(i = 0; i < embeds.length; i++) {
			embeds[i].style.visibility = 'hidden';
		}
		
		for(i = 0; i < objects.length; i++) {
			objects[i].style.visibility = 'hidden';
		}
	}else{
		for(i = 0; i < embeds.length; i++) {
			embeds[i].style.visibility = 'visible';
		}
		
		for(i = 0; i < objects.length; i++) {
			objects[i].style.visibility = 'visible';
		}	
	}

}


var currentSlide = '';
function swapSlide(id){
		
	$$('.contentPanel').each(
	function(element)
	 {
		 //alert(element.id+" "+element.getStyle('z-index'));
		 //var mySlider = new Fx.Slide(element, {mode:'horizontal',duration: 700, transition: Fx.Transitions.Back.easeIn});
		 //var mySlider = new Fx.Slide(element,{duration: 1000, transition: Fx.Transitions.expoOut}).hide();
		 var myFader = new Fx.Style(element, 'opacity', {duration: 750, wait: false}).set(0);
if(id == "processPanel"){
				document.getElementById("processPanel").style.zIndex = '5';
			}
if(id == "peoplePanel"){
				document.getElementById("peoplePanel").style.zIndex = '5';
			}			
		 // this should hide all if there's no id
		 if( (element.id != id) && (element.getStyle('z-index') != '4') ){
			 //element.setStyle('z-index','2');
			 //element.fx = new Fx.Slide(element, {mode:'horizontal',duration: 700, transition: Fx.Transitions.Back.easeIn}).hide();
			 //element.fx.slideOut();
			 //element.setStyle('display','none');
			 myFader.start(0);
		 // this should affect only the currently shown slide
		 }else if( (element.getStyle('z-index') == 4) && (element.id != id) ){
			 //alert(element.id);
			 //element.setStyle('z-index','2');
			 //element.fx = new Fx.Slide(element, {mode:'horizontal',duration: 700, transition: Fx.Transitions.Back.easeIn}).show();
			 //element.fx.slideOut();
			 //element.setStyle('display','none');
			 myFader.start(0);
		 // this should only affect the id being passed to the function
		 }else if(element.getStyle('z-index') != '4'){
			 //element.fx = new Fx.Slide(element, {mode:'horizontal',duration: 700, transition: Fx.Transitions.linear}).hide();	
			 //element.fx.slideIn(); 
			 //element.setStyle('z-index','4');
			 //element.setStyle('display','block');
			 myFader.start(1);
			 if(id != "portfolioPanel"){
				$('portfolioItemTitle').innerHTML = '';
				portfolioItemCurrent = "";
				$$('.current').each(
				function(element)
				 {
					 element.removeClass('current');
				 }
				 );
				$('portfolioPanel').setHTML('');
			}
			if(id == "homePanel"){
				if(currentSlide != ""){
				//myShow.start();
				//alert('we are starting the slideshow on subsequent home page visit');
				var startMyShow = (function(){ myShow.start(); }).delay(5000);
				}
			}else{
				// beat it to death
				var stopMyShow = function(){ myShow.stop(); }	 
				stopMyShow = (function(){ myShow.stop(); }).delay(1000);
				stopMyShow = (function(){ myShow.stop(); }).delay(2000);
				//myShow.stop();
			}
			
		 }
	 });
	currentSlide = id;
}
function buildSlideShow(){
	// we look for all the carousel_6_item elements
	var carItems = $$('div.carousel_6_item');
	//alert(carItems.length);
	
	// we find out how many spreads there are in each
	carItems.each(
		function(element){
			var spreads = $$('#'+element.id+' .spread');	
			//var spreads = element.getChildren().filterByClass('spread');
			//alert(spreads.length);
			if(spreads.length > 1){
				
				var prevLink = new Element('a', {
					//'id': 'note',
					'class': 'prevLink disabledArrow'
					});
				prevLink.setHTML('&nbsp;');
				prevLink.injectInside(element);
				
				var nextLink = new Element('a', {
					//'id': 'note',
					'class': 'nextLink'
					});
				nextLink.setHTML('&nbsp;');
				nextLink.injectInside(element);
				//alert(element.innerHTML);
				
				element.spreadShow = new SimpleSlideShow({
				  startIndex: 0,
				  slides: spreads,
				//  currentIndexContainer: '', //an element or it's id
				//  maxContainer: '',
				  nextLink: nextLink,
				  prevLink: prevLink,
				  wrap:false,
				  disabledLinkClass:'disabledArrow',
				  currentSlideClass:'currentSpread',
				  crossFadeOptions: {
					duration: 250
				}
				});
				
			}
		}
		);
}

function ChangePhoto (oldimg, newimg) {

   document.images[oldimg].src=newimg;

}

function imgSwap(oImg)
{
   var strOver  = "_on"    // image to be used with mouse over
   var strOff = "_off"     // normal image
   var strImg = oImg.src
   if (strImg.indexOf(strOver) != -1) 
      oImg.src = strImg.replace(strOver,strOff)
   else
      oImg.src = strImg.replace(strOff,strOver)
}

function fadePeople(){
var staffElem=document.getElementById('peoplePanel');
var myFader = new Fx.Style(staffElem, 'opacity', {duration: 750, wait: false}).set(0);
myFader.start(1);
}

function homeJim() {
ChangePhoto('staff','images/people/jim.jpg'); 
ChangePhoto('subnav_people','images/people/nav2_jim.jpg');
var el = document.getElementById('staff_home_nav');
el.style.display='none';	
document.getElementById('staff_sub_nav').style.display='block';
fadePeople();
}
function homeTom() {
ChangePhoto('staff','images/people/tom.jpg'); 
ChangePhoto('subnav_people','images/people/nav2_tom.jpg'); 
var el = document.getElementById('staff_home_nav');
el.style.display='none';	
document.getElementById('staff_sub_nav').style.display='block';
fadePeople();
}
function homeChris() {
ChangePhoto('staff','images/people/chris.jpg'); 
ChangePhoto('subnav_people','images/people/nav2_chris.jpg'); 
var el = document.getElementById('staff_home_nav');
el.style.display='none';	
document.getElementById('staff_sub_nav').style.display='block';
fadePeople();
}
function homeLainie() {
ChangePhoto('staff','images/people/lainie.jpg'); 
ChangePhoto('subnav_people','images/people/nav2_lainie.jpg'); 
var el = document.getElementById('staff_home_nav');
el.style.display='none';	
document.getElementById('staff_sub_nav').style.display='block';
fadePeople();
}
function homeHome() {
ChangePhoto('staff','images/people/staff.jpg'); 
var el = document.getElementById('staff_home_nav');
el.style.display='block';	
document.getElementById('staff_sub_nav').style.display='none';
fadePeople();
}

