Event.observe(window, 'load', function() {
	if($('content_subnav4')){
		Event.observe($('content_subnav4'),'click',function(){slideNav(4)});
	}
	if($('content_subnav5')){
		Event.observe($('content_subnav5'),'click',function(){slideNav(5)});
	}
	if($('content_subnav6')){
		Event.observe($('content_subnav6'),'click',function(){slideNav(6)});
	}
	if($('content_subnav7')){
		Event.observe($('content_subnav7'),'click',function(){slideNav(7)});
	}
	if($('content_subnav8')){
		Event.observe($('content_subnav8'),'click',function(){slideNav(8)});
	}
	if($('content_subnav9')){
		Event.observe($('content_subnav9'),'click',function(){slideNav(9)});
	}
	
	if($('home')){//Home page body id
		//setTimeout("startSlideShowRange('slide',1,3,6000);", 2000);
		startSlideShowRange('slide',1,3,9000);
		setTimeout("startSlideShow('testimonial',1,8000);", 3500);
	}

});


function viewHTML(viewId, codeId) {
	var src, dst, temp;
	if (src = document.getElementById(codeId))
		if (dst = document.getElementById(viewId)) {
			if (dst.innerHTML != '') {
				dst.innerHTML = '';
				return;
			}
			code = src.innerHTML;
			code = code.replace("<", "&lt;");
			dst.innerHTML = "// Insert this code in the HTML of your webpage." + code;
		}
}

var noFocusObj = null;

function noFocus() {
	if (!noFocusObj)
		noFocusObj = document.getElementById("nofocus");
	if (noFocusObj)
		noFocusObj.blur();
}


//Slideshow functions.

var currentSlideId = 1; 

function showScreen() {
	var scrollTop = getScrollingPosition()[1];
	var size = getPageSize();
	document.getElementById('screen').style.height = size[1] + "px";
	showObj('screen');
	$("nofocus").focus();
}

function showNthSlideshow(param) {
	showScreen()
	var scrollTop = getScrollingPosition()[1];
	var size = getPageSize();
	var trialDialogTop = scrollTop + (size[3] - 361) / 2;
	document.getElementById('slideshowDialog' + param).style.top = trialDialogTop + "px";
	showObj('slideshowDialog' + param);
}

function showSlideshow(){
	showNthSlideshow('');
}

function slideshowNav(slideId){
	noFocus();
	if(slideId>8 || slideId<1){
		return;
	}
	hideObj('slide'+currentSlideId);
	showObj('slide'+slideId);
	if(slideId<=2){
		$('stripthumbsframe').scrollLeft=0;
	}
	if(slideId>=7){
		$('stripthumbsframe').scrollLeft=125;
	}
	$('thumbs'+currentSlideId).removeClass('currimage');
	$('thumbs'+currentSlideId).addClass('notcurrimage');
	$('thumbs'+slideId).removeClass('notcurrimage');
	$('thumbs'+slideId).addClass('currimage');
	
	$('pagenum').value = slideId;
	currentSlideId = slideId;
}

function slideshowClose() {
  hideObj('slideshowDialog');
  hideObj('slideshowDialog2');
  hideObj('screen');
  // loginFocus();
}

function insertMovie(movieIndex) {

	switch (movieIndex) {
		case 2:  movie = "retouch2"; break;
		case 3:  movie = "archive3"; break;
		case 4:  movie = "stock";    break;
		case 5:  movie = "color2";   break;
		default: movie = "edit2";
	}
  var ident = "marketing_movie_" + movieIndex; // PMJ Oct 21, 2009
  document.write('<embed src="/video/' + movie + '.mov" id="' + ident + '" name="' + ident + '" enablejavascript="true" width="656" height="385" autoplay="true" controller="true"></embed>');
  
}

function showThumbMovie(movieIndex){
	var scrollTop = getScrollingPosition()[1];
	var size = getPageSize();
	var movieDialogTop = scrollTop + (size[3] - 361) / 2;
	document.getElementById('screen').style.height = size[1] + "px";
	document.getElementById('movieDialog').style.top = movieDialogTop + "px";
	showObj('screen');
	showObj('movieDialog');
	
	for (var i = 1; i <= 7; i++){
		if(i == movieIndex){
			removeSubClass('movie'+i, 'hidden');
		}
		else{
			addSubClass('movie'+i, 'hidden');
		}
	}
}

function movieDialogClose() {
  hideObj('movieDialog');
  hideObj('screen');
  try {
	  if (document.marketing_movie_1) // PMJ Oct 21, 2009 - windows keeps playing video
  		document.marketing_movie_1.Stop();
	  if (document.marketing_movie_2)
  		document.marketing_movie_2.Stop();
	  if (document.marketing_movie_3)
  		document.marketing_movie_3.Stop();
	  if (document.marketing_movie_4)
  		document.marketing_movie_4.Stop();
	  if (document.marketing_movie_5)
  		document.marketing_movie_5.Stop();
	  if (document.marketing_movie_6)
  		document.marketing_movie_6.Stop();
  }
  catch(e) {};
}

function demoQuery(subscription) {
	var scrollTop = getScrollingPosition()[1];
	var size = getPageSize();
	var trialDialogTop = scrollTop + (size[3] - 361) / 2;
	document.getElementById('screen').style.height = size[1] + "px";
	document.getElementById('trial_option_dialog').style.top = trialDialogTop + "px";
	showObj('screen');
	showObj('trial_option_dialog');
	$("nofocus").focus();
}
function demoRequestSubmit() {
	if (getObjValue('d_firstname') == '' || getObjValue('d_lastname') == '' || getObjValue('d_email') == '' || validateEmail(getObjValue('d_email')) != true)
		alert("Please enter your name and a valid email address.");//More validation is in ajax file for dupe username.
	else { 
	loginAjax('action=request_demo_account&first_name='+getObjValue('d_firstname')+'&last_name='+getObjValue('d_lastname')+'&email='+getObjValue('d_email'));
		setObjValue('d_firstname', '');
		setObjValue('d_lastname', '');
		setObjValue('d_email', '');
	}
}
function demoRequestClose() {
  hideObj('trial_option_dialog');
  hideObj('screen');
  // loginFocus();
}

function loginAjax(s) {
  var xmlhttp = getHTTPObject();
  xmlhttp.open("GET", "/login_ajax.php?" + s);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
      if (xmlhttp.status == 200) {
        response = xmlhttp.responseText;
        eval(response);
      }
    }
  }
  xmlhttp.send(null);
}

function trySetInnerHTML(domId, theHTML) {
	try {
		setInnerHTML(domId, theHTML);
	}
	catch(e) {}
}

function fixLanguage() {
	//	return;
	// alert("fixLanguage");
	// trySetInnerHTML("title_language", "Language");
	trySetInnerHTML("title_german",   "Deutsch");
	trySetInnerHTML("title_english",  "English");
	trySetInnerHTML("title_spanish",  "Español");
	trySetInnerHTML("title_french",   "Français");
	trySetInnerHTML("title_italian",  "Italiano");
	trySetInnerHTML("title_dutch",    "Nederlands");
	trySetInnerHTML("title_portuguese", "Português");
	trySetInnerHTML("title_chinese",  "汉");
	trySetInnerHTML("title_japanese", "日本語");
}

function pageStart() {
	var url = "" + document.location; // document.location;
	var translating = url.indexOf("babelfish") > 0;
	if (!translating) {
		setTimeout("showObj('mcafee');", 10);
	}
	else {
		try {
			var obj;
			if (obj = $('translate_link')) {
				obj.href = baseURL + "public/index.php";
				obj.innerHTML = "English";
			}
			if (obj = $('login_iframe'))
				obj.src = baseURL + "simple_login.php?css=marketing";
		}
		catch (e) {}
	}
	setTimeout("fixLanguage();", 250);
}

addLoadEvent(pageStart);

function selectLanguage(param) {
	// http://66.163.168.225/babelfish/translate_url_content?.intl=us&lp=en_es&trurl=http%3a%2f%2fdev.liveedit.com%2fpublic%2findex.php
	if (param == "en_en")
		document.location = baseURL + "public/index.php";
	else {
		var baseURLuri = encodeURIComponent(baseURL);
		// document.location = "http://66.163.168.225/babelfish/translate_url_content?.intl=us&lp=" + param + "&trurl=http%3a%2f%2fdev.liveedit.com%2fpublic%2findex.php";
		document.location = "http://66.163.168.225/babelfish/translate_url_content?.intl=us&lp=" + param + "&trurl=" + baseURLuri + "%2fpublic%2findex.php";
	}
}


function addSubClass(id, subClass) {
	var obj = document.getElementById(id);
	if (obj)
		obj.className = trim(obj.className.replace(subClass, "")) + subClass; // only add once!!
}

function removeSubClass(id, subClass) {
	var obj = document.getElementById(id);
	if (obj) {
		obj.className = trim(obj.className.replace(subClass, ""));
		obj.className = trim(obj.className.replace(trim(subClass), "")); // handle case where adding and removing " b" from either "a" or "".
	}
}


function detailNav(id){
	if($('feature'+id)){
		//If you are past the bottom or top, stop
		if($('feature'+id).parentNode.className.indexOf('hidden') == -1){
		
			//Nav
			addSubClass('feature'+activeId, ' nav');
			removeSubClass('feature'+id, ' nav');
			
			//Subhead
			addSubClass('heading'+activeId, ' hidden');
			removeSubClass('heading'+id, ' hidden');
	
			
			//Text below movie
			addSubClass('movieText'+activeId, ' hidden');
			removeSubClass('movieText'+id, ' hidden');
			
					
			//Swap movie poster start.  Always replace movie with image.
			addSubClass('poster'+activeId, ' hidden');
			removeSubClass('poster'+id, ' hidden');
			
			//Since there are so many movies, clear movie embed out on nav.
			if($("movie"+activeId)){
				addSubClass('movie'+activeId, ' hidden');
				$("movie"+activeId).innerHTML = '';
			}
			
			//Movie.
			addSubClass('movieContainer'+activeId, ' hidden');
			removeSubClass('movieContainer'+id, ' hidden');
			
			//Reset active Id
			activeId = id;
		}
	}
}

function navPaging(id){
	//Make sure nav page exits;
	if($('navPage'+id)){
		addSubClass('navPage'+activePageId, ' hidden');
		removeSubClass('navPage'+id, ' hidden');
		if(id==1){
			detailNav(1);
		}
		else if(id==2){
			detailNav(13);
		}
		activePageId = id;
	}

}

function swapMov(id){
	if($("movie"+id)){
		$("movie"+id).innerHTML =  '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="540" height="335" codebase="http://www.apple.com/qtactivex/qtplugin.cab"> <param name="src" value="/public/video/features/feature_movie'+id+'.mov"> <param name="autoplay" value="true"> <param name="controller" value="true"> <param name="loop" value="false"> <embed id="movEm" src="/public/video/features/feature_movie'+id+'.mov" width="540" height="335" autoplay="true" controller="true" loop="false" pluginspage="http://www.apple.com/quicktime/download/"> </embed></object>';	
		addSubClass('poster'+activeId, ' hidden');
		removeSubClass('movie'+id, ' hidden');
	}
}
	

function promoSlideClick() {
	document.location = "promo.php";
}


function slideShow(slideName,stopNumber){
	var number = 1;
	var obj = $(slideName + number);
	while (obj) {
		if (number>=stopNumber){
			return;
		}
		else if (isVisibleObj(slideName + number)) {
			hideObj(slideName + number);
			if ($(slideName + (number+1))){
				showObj(slideName + (number+1));
				if(slideName + (number+1) == 'slide3'){
					showObj('content_subnav');
				}
			}
			else {
				showObj(slideName + 1);
			}
			return;
		}
		number += 1;
		
		obj = $(slideName + number);
	}	
	return;
}

function startSlideShow(slideName, startNumber, interval){
	setInterval( "slideShow('"+slideName+"')", interval);
}

function startSlideShowRange(slideName, startNumber, stopNumber, interval){
	setInterval( "slideShow('"+slideName+"',"+stopNumber+")", interval);
}

function shirtPop(shirtId){
	winPop('/public/shirt.php?shirtId='+shirtId,'shirtpop','resizable=0','540','520');
}

function loginBegins() {
	showObj("login_notes");
}

function supportNav(id){
		if($('sub'+id)){
			addSubClass('sub'+activeId, ' hidden');
			removeSubClass('subNav'+activeId, ' supportNavOn');
			removeSubClass('sub'+id, ' hidden');
			addSubClass('subNav'+id, ' supportNavOn');
			activeId = id;
		}
}

var activeSlideId = 3;

function slideNav(slideId){
	if(activeSlideId != slideId){
		showObj('slide' + slideId);
		hideObj('slide' + activeSlideId);
		addSubClass('content_subnav'+slideId, 'content_subnav_on');
		removeSubClass('content_subnav'+activeSlideId, 'content_subnav_on');
		activeSlideId = slideId;
	}
}

//Overview movies.
function showMov(id){
	//Write into and wipe out embed/object tag as ie seems to continue playing if you just hide the movie.
	$('vid'+id).update('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="164" height="108" codebase="http://www.apple.com/qtactivex/qtplugin.cab" id="movieThumb'+id+'"> <param name="src" value="/public/video/overview/overview'+id+'_sm.mp4"> <param name="autoplay" value="true"> <param name="wmode" value="transparent"> <param name="controller" value="false"> <param name="loop" value="false"> <embed src="/public/video/overview/overview'+id+'_sm.mp4" name="movieThumb'+id+'" width="164" height="108" autoplay="true" controller="false" loop="false" pluginspage="http://www.apple.com/quicktime/download/"> </embed></object>');
}

function hideMov(id){
	//Write into and wipe out embed/object tag as ie seems to continue playing if you just hide the movie.
	$('vid'+id).update();
}

function validateEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test((email))){
		return true;
	}
}


