/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
MISC
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var ismobile=(Browser.Platform.android==true || Browser.Platform.ios==true ? true : false);
var flashEnabled=(Browser.Plugins.Flash==false || Browser.Plugins.Flash.version<9 ? false : true);

window.addEvent('domready', function() {
	if ($("feedback")) $("feedback").setStyle("display","block");
	
	$$("div.loader1","div.loader2","div.loader3","div.loader4").setStyle("display","none");
	
	// MOBILE
	if (ismobile==true){
		$("header").addClass('header_mobile');
		$("wrapper").addClass('wrapper_mobile');
		$("dialogContainer").addClass('dialog_mobile');
		$("dialogContainer").addClass('dialog_mobile');
		$("push").addClass('push_mobile');
		if ($("feedback")) $("feedback").setStyle("display","none");
	}
	
	// IE6
	if (Browser.name=='ie' && Browser.version=='6'){
		alert("We have detected that you are using IE6. Please upgrade your browser before using our site.");	
	}
	
	// NOTIFICATIONS
	if ($(document.body).getElement('div.status')){
		// LINKS
		$(document.body).getElements('div.status').getElements('a').each(function(el){
			el.addEvent('click',function(){
				if (this.get('id')!='no_close'){ // Don't close stopper
					var elem=this.getParent('div.status');
					elem.fade('0');
					var myFx = new Fx.Tween(elem, {duration: '200'});
					myFx.start('height', 0).chain(function(){
						OverText.update();
					});
					// IF ALT TAG, RUN EXTRA FUNCTION
					if (this.getAttributeNode('alt')){
						var altTag = this.getAttributeNode('alt').nodeValue;
						if (altTag!=null && altTag!='')
							statusResult(altTag,this.id);
					}
				}
			});
		});
	}
});


/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
STATUS OPTIONS
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

function statusResult(type,answer){
	// SAVE SECTION AS HOME PAGE
	if (type=='save_section'){ // BOOKMARK HOMEPAGE
		if (answer=='yes')
		var sectionCookie = Cookie.write('section', section, {duration: 365});
		else if (answer=='no')
		var sectionCookie = Cookie.write('section', 'disable', {duration: 365});
	}
	// NEED HELP BOX STOP SHOWING
	if (type=='needHelp_close'){ // BOOKMARK HOMEPAGE
		ajax_execute('','disableNotifications','value=needHelp');
	}
}


// DISABLE SELECTION
function disableSelect(el){	
    if(el.attachEvent){
        el.attachEvent("onselectstart",disabler);
    } else {
        el.addEventListener("mousedown",disabler,"false");
    }
}
function enableSelect(el){
    if(el.attachEvent){
        el.detachEvent("onselectstart",disabler);
    } else {
        el.removeEventListener("mousedown",disabler,"false");
    }
}
function disabler(e){
    if(e.preventDefault){ e.preventDefault(); }
    return false;
}
function ordi(n){
return n+(arguments.callee.map[n]||"th");
}
ordi.map={1:'st',21:'st',31:'st',2:'nd',22:'nd',3: 'rd',23:'rd'};

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
AJAX
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var myRequest;
function ajax_execute(div,func,data,fade,erase){
	if(myRequest) myRequest.cancel();
	myRequest = new Request({
								
		method: 'post', evalScripts: true, url: uriDir+'_php/ajax_display.php',
		
		onRequest: function(){
			
			// IF LOADING ICON EXISTS, SHOW IT
			if (document.id(div+'_loading'))
				loadingSet=setTimeout("document.id('"+div+"_loading').setStyle('display','')",10);
			if (fade=='true'){
				var myElement=document.id(div);
				myElement.setStyle('opacity','0');
			}
			if (document.id(div) && div!='' && (erase=='true' || page=='account')) { document.id(div).empty();}
		},
		
		onSuccess: function(responseText, responseXML) { 
			// IF LOADING ICON EXISTS, HIDE IT
			if (document.id(div+'_loading')){
				clearTimeout(loadingSet);
				document.id(div+'_loading').setStyle('display','none');
			}
			// IF FADE
			if (fade=='true'){
				var myElement=document.id(div);
				myElement.tween('opacity',[0,1]);
			}
			
			if (document.id(div) && div!='') { document.id(div).set('html',responseText);}

		} 
		
	});
	
	myRequest.send('func='+func+'&'+data);
	
}


/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 NAVIGATION DROPDOWN
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var membersMenu=null;
window.addEvent('domready', function() {
	
	turnOnMenu();
	
});
function turnOnMenu(){
	if ($('membersMenu')){
		  membersMenu = new Fx.Slide('membersMenu',{
			duration: 400,
			transition: Fx.Transitions.Pow.easeOut  
		  }).hide();
		  
		  var membersOpen = function(event){
			$$('.menuContainer').setStyle('display','block');
			membersMenu.stop();
			$('membersOn').addClass('arrowOn');
			membersMenu.slideIn().chain(function(){
				$('membersOn').removeEvent('click',membersOpen);
				$('membersOn').addEvent('click',membersClose);
			});
		  }
		  var membersClose = function(event){
			membersMenu.stop();
			membersMenu.slideOut();
			$('membersOn').removeClass('arrowOn');
			$('membersOn').removeEvent('click',membersClose);
			$('membersOn').addEvent('click',membersOpen);
		  }
		  
		  $('membersOn').addEvent('mouseenter', membersOpen);
		  $('membersOff').addEvent('mouseleave', membersClose);
		  if (section=='account')
		  $('membersOff').addEvent('click', membersClose);
	}
}
/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 DIALOG BOX
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/
var dialogLock='off';
function dialog(state){
	if (state=='on'){
		$('dimmer').setStyle('display','inline');
		$('dimmer').fade('.6');
		dialogFX.slideIn();
	}
	else if ((state=='off' && dialogLock=='off') || state=='forceOff'){
		$('dimmer').fade('out');
		setTimeout("$('dimmer').setStyle('display','none');",300);
		dialogFX.slideOut();
	}
}
// SET INITIAL SETTINGS
window.addEvent('domready',function(){
	// DIMMER
	$('dimmer').fade('hide');
	$('dialog').setStyle('display','block');
	
	// DIALOG
	dialogFX = new Fx.Slide('dialog',{
		transition: Fx.Transitions.Pow.easeOut  
	}).hide();
	 $('dialogContainer').addEvent('click',function(){
		  dialog('off');
	 });
	  $('dialog').addEvent('mouseenter',function(){
		  dialogLock='on';
	 });
	 $('dialog').addEvent('mouseleave',function(){
		  dialogLock='off';
	 });
});

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 LOGIN
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var loginMove;
window.addEvent('domready',function(){
	login_form = new FormCheck('form_loginForm',{
		submitByAjax:true,
		ajaxEvalScripts:true,
		onAjaxRequest:function(){
			$('login').setStyle('display','none');
			$('login_register').setStyle('display','none');
			$('loginProcessing').set('html','<img src='+uriDir+'_media/images/loader5.gif> Verifying your access information...');
			$('loginProcessing').setStyle('display','inline-block');
		}
	});
	forgot_form = new FormCheck('form_forgot',{
		submitByAjax:true,
		submit:false,
		ajaxEvalScripts:true,
		onAjaxRequest:function(){
			$('login').setStyle('display','none');
			$('login_register').setStyle('display','none');
			$('loginProcessing').set('html','<img src='+uriDir+'_media/images/loader5.gif> Looking up your information. Please wait...');
			$('loginProcessing').setStyle('display','inline-block');
		}
	});
});
function forgotPass(state){
	loginMove = new Fx.Tween('loginInner', {
		duration: 'long',
		transition: Fx.Transitions.Pow.easeOut ,
		link: 'cancel',
		property: 'left'
	});
	if (state=='go')
	loginMove.start('0px','-280px');
	else
	loginMove.start('-280px','0px');
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 PASSWORD RESET
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

if (section=='reset-password'){	
	var avlock;
	window.addEvent('domready',function(){	
		var reset_password = new FormCheck('passwordForm');
	});
}

function confirmPass(el) {
	if( avlock )  return true;
	avlock = true;
	
	
	if( $("password").value!=$("password2").value ) {
		var errorMsg = "Passwords do not match.";
		el.errors.push( errorMsg );
		avlock = false;
		return false;
	}
	
	var password = $("password").value;
	var digitTrue=false;
    for (var i = 0; i < password.length;i++){
	   if (parseInt(password.charAt(i))==password.charAt(i))
        	digitTrue=true;
    }
	if (digitTrue==false ){
		var errorMsg = "Password must contain at least one digit.";
		el.errors.push( errorMsg );
		avlock = false;
		return false;
	}
	
	avlock = false;
	return true;
}


/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 TIPS
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

window.addEvent('domready',function(){	
	var myTips = new Tips($$(".Tips"), {
		showDelay: 100,
		hideDelay: 100,
		fixed: true,
		offset: {"x": -19, "y":-59},
		onHide: function(tip, el){
			tip.fade("out").get("tween").chain(function(){
				tip.setStyle("display", "none");
			})
		},
		onShow: function(tip, el){
			if (el.id=="nameTip")
				$$(".tip").setStyle("marginTop","-30px");
			else if (el.id=="passTip")
				$$(".tip").setStyle("marginTop","-48px");
			else
				$$(".tip").setStyle("marginTop","0px");
			tip.setStyles({
				display: "block"
			}).fade("in");
		}
	});
});

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 HOME
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

if (section=='home' && page=='home'){
	window.addEvent('domready',function(){	
		$$('div.benefits').addEvent('click',function(){
			window.location='./solutions';
		})
	
	})
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 REGISTER
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

if (section=='register'){
	window.addEvent('domready',function(){	
		// ADD CLICK TO NEW/EXISTING COMPANIES
		if ($("companyType")) $("companyType").getElements("input").addEvents({
			"click":function(){
				if (this.id=="existing"){
					$("companyExist").setStyle("display","inline");
					$("companyNew").setStyle("display","none");
					register_form.dispose($("companyNew"));
					register_form.register($("companyExist"));
				}
				else {
					$("companyExist").setStyle("display","none");
					$("companyNew").setStyle("display","inline");
					register_form.register($("companyNew"));
					register_form.dispose($("companyExist"));
				}
			}
		});
		
		// REVEAL COMPANIES IF CORPORATE SELECTED
		var myFx = new Fx.Tween($("companyInputs"), {
			duration: "200",
			transition: "quad:out",
			link: "cancel",
			property: "height"
		});
		
		// ADD CLICK TO USER/CORPORATE ACCOUNTS
		if ($("accountType")) 
			$("accountType").addEvents({
				"click" : function(){
					if (this.checked==false){
						myFx.stop();
						myFx.start(0);
						register_form.dispose($("companyPosition"));
						register_form.dispose($("companyNew"));
						register_form.dispose($("companyExist"));
					}
					else {
						myFx.stop();
						myFx.start(160);
						if (register_form) {
							register_form.register($("companyPosition"));
							register_form.register($("companyExist"));
						}
					}
				}
			});
	});
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 FORMCHECK FUNCTIONS
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var avlock = false;

function existData(el) {
	if( avlock )  return true;
	avlock = true;

	data=el.value;
	
	// CHECK IN DATABASE
	var req = new Request({
		url: uriDir+"_php/ajax_display.php",
		async: false,
		method: "post"
	 }).send("func=form_check&formName=userForm&input="+el.name+"&data=" + data);
	
	if( req.response.text == "1" ) {
		var errorMsg = (el.name == "username" ?
			"This username is already taken." : "");
		var errorMsg = (el.name == "email" ?
			"There is already an account with this email address." : "");
		el.errors.push( errorMsg );
		avlock = false;
		return false;
	}
	
	
	avlock = false;
	return true;
}
function fdaApproval(el){
	var fdaTest=0;
	$("fdaContainer").getElements('input').each(function(elem){
		if (elem.checked==true)
			fdaTest=1;
	});
	if (fdaTest==1)
			return true;
	else {
		var errorMsg = "Your product MUST be government approved in order to post on our site.";
		el.errors.push( errorMsg );
		avlock = false;
		return false;	
	}
}
function validateEmail(el){
	if ($("accountType").checked==true){
		var domain = el.value.replace(/.*@/, "");
		var remove=domain.lastIndexOf(".");
		domain=domain.substring(0,remove).toLowerCase().replace(/_/g," ").replace(/-/g," ").replace(/\./g," ");
		domainArray=domain.split(" ");
		
		if ($("existing").getProperty("checked")==true) var companyValue=$("companyExist").value; else var companyValue=$("companyNew").value;
		
		companyValue=companyValue.toLowerCase().replace(/-/g," ").replace(/_/g," ").replace(/\./g," ");
		companyValueArray=companyValue.split(" ");
		
		for (var i=0;i<companyValueArray.length;i++){
			if (companyValueArray[i]==domainArray[0].substr(0,companyValueArray[i].length) || isFound==true){
				var isFound=true;
			}
			else
				var isFound=false;
		}
			
		// if no value
		if (companyValue=="") isFound=false;
		
		// EXCEPTIONS
		if (domain=="its jnj")
		isFound=true;
		
		if (isFound == false){
			var errorMsg = "Your email must be associated with the company below. Please use your corporate email address. (ie. Stryker = jon@stryker.com)";
			el.errors.push( errorMsg );
			avlock = false;
			return false;
		}
	}
	else
	return true;
}


function checkSection(el) {
	if( avlock )  return true;
	avlock = true;
	
	var inputsChecked=0;
	var inputs=document.getElements("input.inputSection");
	for (var i=0; i<inputs.length; i++){
		if (inputs[i].checked=="1")
		inputsChecked = 1;	
	}
	
	if( inputsChecked == 0 ) {
		var errorMsg = "Please check a box.";
		el.errors.push( errorMsg );
		avlock = false;
		return false;
	}

	avlock = false;
	return true;
}



function confirmEmail(el) {
	if( avlock )  return true;
	avlock = true;
	
	
	if( $("email").value!=$("email2").value ) {
		var errorMsg = "Confirm email address does not match.";
		el.errors.push( errorMsg );
		avlock = false;
		return false;
	}
	
	avlock = false;
	return true;
}

function existCompanyForm(el) {
	if( avlock )  return true;
	avlock = true;
	
	data=el.value;
	
	// CHECK IN DATABASE
	var req = new Request({
		url: uriDir+"_php/ajax_display.php",
		async: false,
		method: "post"
	 }).send("func=form_check&input=" + el.name + "&data=" + data);
	
	if( req.response.text == "1" ) {
		if (el.name == "email")
		var errorMsg = "Email address is already taken.";
		else if (el.name == "username")
		var errorMsg = "Username is already taken.";
		else if (el.name == "companyNew")
		var errorMsg = "This company already exists.";
		el.errors.push( errorMsg );
		avlock = false;
		return false;
	}

	avlock = false;
	return true;
}


function valMenu(el){
	if (el.value=="default"){
		return false;
	}
	else
	return true;	
}
function checkSection(el) {
	var inputsChecked=0;
	var inputs=document.getElements("input.inputSection");
	for (var i=0; i<inputs.length; i++){
		if (inputs[i].checked=="1")
		inputsChecked = 1;	
	}
	
	if( inputsChecked == 0 ) {
		var errorMsg = "Please check a box.";
		
		el.errors.push( errorMsg );
		return false;
	}
	return true;
}
	
/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 HOME FEATURED ITEMS
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var selectAutoTime;
var fadeIn; var fadeOut;
clearTimeout(selectAutoTime);
var numGlobal=1;
selectAutoTime = setTimeout('selectAuto()',6000);
window.addEvent('domready',function(){	
	if ($("selectorLoad"))
	setTimeout('$("selectorLoad").destroy()',500);
});
function selectAuto(){
	if ($('selector')) selectSponsored(numGlobal,$("selectorItem_"+numGlobal).getProperty('alt'),'false');	
	selectAutoTime = setTimeout("selectAuto()",6000);
}
function selectSponsored(num,urlPrint,clicked) {
	
	// IF YOU CLICK ON IT
	if (clicked=='true'){
		clearTimeout(selectAutoTime);
		selectAutoTime = setTimeout("selectAuto()",6000);
	}
	
	var myElement=$("selectorImage");
	
	if (fadeOut) fadeOut.cancel();
	if (fadeIn) fadeIn.cancel();
	
	fadeIn = new Fx.Tween(myElement);
	fadeOut = new Fx.Tween(myElement, {
		link:'cancel',
		onComplete: function(e){
			var element=$("selectorImage");
			// CHANGE IMAGE
			//alert($("selectorItem_"+num));
			var itemID = $("selectorItem_"+num).getAttributeNode('name').nodeValue;
			element.setProperty("src","./_content/products/"+itemID+"/sponsor/sponsor-full.jpg");
			element.removeEvent("click");
			element.addEvents({
				'click': function() { 
					
					window.location="./"+section+"/products/"+urlPrint;
				}
			});
			// ONCE SELECTOR STOPS, FADE IN
			fadeIn.start('opacity',1);
		}});
	
	fadeOut.start('opacity',[1,0]);
	
	if (clicked=='true') {
		numGlobal=num;
	}
	
	// MOVE SELECTOR
	$('selector').set('tween', {transition: Fx.Transitions.Quint.easeOut});
	$('selector').tween('margin-top', num*66);
	
	// CHANGE COLOR OF BG
	$('selectorItem_'+numGlobal).tween('color','#FFF');
	$('selectorItem_'+numGlobal).setStyle('text-shadow','#2f445c -1px -1px 0px');
	
	// CHANGE OTHERS BACK
	for (var i=0;i<4;i++){
		if (numGlobal!=i) { 
			$('selectorItem_'+i).tween('color','#40556d');
			$('selectorItem_'+i).setStyle('text-shadow','#FFF -1px -1px');
		}
	}
	
	// SET LOOP SO IT WILL GO BACK TO ONE
	numGlobal++;
	if (numGlobal=='4') numGlobal=0;
}


/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 COMPANIES
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

window.addEvent('domready',function() {
	if (page=='companies'){
		(function() {
			var companySearch=new OverText('search',{
				positionOptions: {
					offset: {
						x: 3,
						y: 1
					}
				},
				labelClass: 'companySearch_overtext'
			});
		}).delay(0);
	}
});
function toLetter(letter){
	if ($(letter))
	var myFx = new Fx.Scroll(window).toElement($(letter));
	else
	alert('There are no companies with this letter');
}
function elementObject(title,shortname,image){
		this.title=title;
		this.shortname=shortname;
		this.image=image;
}
function companyList(){
	
	// get search values
	var userInput = document.id('search').value;
	
	// define new array
	var companyPrint = new Array();
	var letter=null;
	
	// destroy existing objects
	document.id('companyList').empty();
	
	// Search through objects for related items
	if (userInput!=''){
		var a=0;
		for ( k = 0; k < companyArray.length ; k++ ) {
			// check title
			var checkTitle=companyArray[k].title;
			var checkTitleLower=checkTitle.toLowerCase()
			if (checkTitle.indexOf(userInput)!='-1' || checkTitleLower.indexOf(userInput)!='-1')
			{ companyPrint[a] = companyArray[k]; a++ }
		}
	}
	else
		companyPrint=companyArray;
	
	// output new array
	for ( j = 0; j < companyPrint.length ; j++ ) {
		
		// define list element
		var element = new Element('li', {
			'alt':companyPrint[j].shortname,
			'events': {
				'click': function(e){
					window.location="../"+this.get('alt');
				}
			}
		});
		if (companyPrint[j].image!='none')
		var image = new Element('img', {
			'src':companyPrint[j].image,
			'events': {
				'click': function(e){
					window.location="../"+this.title;
				}
			}
		}).inject(element);
		else
		var noImage = new Element('div', {
			'html':'<span>'+companyPrint[j].title+'</span>'
		}).inject(element);
		
		// add text
		element.setProperty('title',companyPrint[j].title);
		
		// if beginning a new letter
		/*
		if (letter!=companyPrint[j].title[0]){
			var header = new Element('li',{ id:companyPrint[j].title[0] });
			header.addClass('companyList_Header');
			if (companyPrint[j].title[0]=='A') header.addClass('top');
			header.appendText(companyPrint[j].title[0]);
			header.inject(document.id('companyList'), 'bottom');
			letter=companyPrint[j].title[0];
		}
		*/
		// inject new content
		element.inject(document.id('companyList'), 'bottom');

	}
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 COMPANIES
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

window.addEvent('domready',function() {
	if (loggedin==true){
		var slideLeft = new  Fx.Morph('feedbackContents', {
			duration: 300 ,
			transition: Fx.Transitions.Sine.easeOut
		});
		var slideBottom = new  Fx.Morph('feedbackSubmit', {
			duration: 300 ,
			transition: Fx.Transitions.Sine.easeOut
		});
	
		var state = '300';
		var state2 = '20';
	
		 document.id('feedbackButton').addEvent('click', function(){
			 document.id('feedbackContents').setStyle('display','');
			 state = (state == 1 ? 300 : 1);
			 state2 = (state == 1 ? 20 : 1);
			 slideLeft.start({
				'left': state+'px',
				'width': 300/state+'px'
			});
			slideBottom.start({
				'top': state2+'px',
				'left': state+'px',
				'width': 300/state+'px'
			});
			document.id('feedSub').value='';
			document.id('feedContent').value='';
		 });
		  document.id('feedbackLeft').addEvent('click', function(){
			 state = (state == 1 ? 300 : 1);
			 state2 = (state == 1 ? 20 : 1);
			 slideLeft.start({
				'left': state+'px',
				'width': 300/state+'px'
			});
			slideBottom.start({
				'top': state2+'px',
				'left': state+'px',
				'width': 300/state+'px'
			});
		 });
	 
		 slideLeft.set({
				'left': state+'px',
				'width': 300/state+'px'
			});
		
		slideBottom.set({
			'top': '1px',
			'left': state+'px',
			'width': 300/state+'px'
		});
		
		// FEEDBACK FORM
		var formcheckFeedback = '';
		formcheckFeedback = new FormCheck('feedbackFormId',{
			onAjaxRequest:function(){
				document.id('feedbackSubmitDiv').set('html','Sending...');
				document.id('feedbackSubmitDiv').setStyle('opacity',.6);
				document.id('feedbackSubmitDiv').removeEvent('click');
			},
			onAjaxSuccess:function(response){
				document.id('feedbackSubmitDiv').set('html','Sent');
				setTimeout("document.id('feedbackButton').fireEvent('click');",1000);
			},
			onAjaxFailure:function(){
				document.id('feedbackSubmitDiv').set('html','Send Failed');
				setTimeout("document.id('feedbackButton').fireEvent('click');",1000);
			},
			onSubmit:function(){
				document.id('feedbackBrowser').value=Browser.name+' '+Browser.version;
				document.id('feedbackPlatform').value=Browser.Platform.name;
			},
			display : {
					scrollToFirst : false
				},
			submitByAjax:true,
			submit:false,
			ajaxEvalScripts:true
		});
	}
});

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 FAVORITE ITEMS
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

function favoriteItem(id,type){
	ajax_execute("","favoriteItem","item_id="+id+"&type="+type);
			document.id('favorite').addClass('on');
			var check=new Element('span').inject(document.id('favorite'),'top');
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
 VALIDATE FORMS
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

function validateForm(type,form) {
	if (type=='deleteComment')
	var content='Are you sure you want to delete your comment?';
	if (type=='deletePhoto')
	var content='Are you sure you want to delete this photo?';
	if (type=='deleteVideo')
	var content='Are you sure you want to delete this video?';
	if (type=='deleteArticlePhoto')
	var content='Are you sure you want to delete this photo?';
	if (type=='deactiveProduct')
	var content='Are you sure you want to deactivate this product?';
	if (type=='deactiveArticle')
	var content='Are you sure you want to deactivate this article?';
	if (type=='deleteProducts')
	var content='Are you sure you want to delete these products?';
	if (type=='deleteArticles')
	var content='Are you sure you want to delete these articles?';
	
	
	var agree=confirm(content);
	if (agree)
		document.id(form).submit();
}
function validateAjaxForm(type,param) {
	if (type=='deleteCompany'){
		var content='Are you sure you want to delete this company? All files will be erased.';
		var agree=confirm(content);
		if (agree)
			ajax_execute("","updateCompany","company_id="+param+"&set=1&type=delete");
	}
	if (type=='resetCompany'){
		var content='Are you sure you want to reset this company?';
		var agree=confirm(content);
		if (agree)
			ajax_execute("","updateCompany","company_id="+param+"&set=1&type=reset");
	}
	if (type=='approveEmail'){
		var content='Are you sure you want to send the administrator an email?';
		var agree=confirm(content);
		if (agree)
			ajax_execute("","updateCompany","company_id="+param+"&set=1&type=approveEmail");
	}
	if (type=='unlinkUser'){
		var content='Are you sure you want to permanently remove this user? This user will receive an email informing them that they have been removed.';
		var agree=confirm(content);
		if (agree)
			ajax_execute("","manageCompanyUser","account_id="+param+"&type=unlink");
	}
	if (type=='acceptUser'){
		var content='Are you sure you want to allow this user to edit company information?';
		var agree=confirm(content);
		if (agree)
			ajax_execute("activeUser_"+param,"manageCompanyUser","account_id="+param+"&type=acceptUser");
	}
	if (type=='declineUser'){
		var content='Are you sure you want to decline this user\'s invitation to edit company information?';
		var agree=confirm(content);
		if (agree)
			ajax_execute("","manageCompanyUser","account_id="+param+"&type=declineUser");
	}
	if (type=='userLevel_Admin'){
		var content='Are you sure you want to edit this user\'s previliges?';
		var agree=confirm(content);
		if (agree)
			ajax_execute("","userLevel","account_id="+param+"&type=admin");
	}
	if (type=='userLevel_User'){
		var content='Are you sure you want to edit this user\'s previliges?';
		var agree=confirm(content);
		if (agree)
			ajax_execute("","userLevel","account_id="+param+"&type=user");
	}
}


/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
PRODUCTS - BROWSER NAVIGATION
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

window.addEvent('domready',function() {
	if (page=='products' && secondpage==''){
		/*
		// STICKY
		window.onscroll=function(e){ 
			var scroll = $(window).getScroll();
			  if (scroll.y > 28 && $('browseSideNav').getStyle('position') != 'fixed'){ 
				$('browseSideNav').setStyles({
					'position':'fixed',
					'marginTop':'-28px'
				}); 
			  }
			  else if (scroll.y < 28 && $('browseSideNav').getStyle('position') != 'absolute') {
				 $('browseSideNav').setStyles({
					'position':'absolute',
					'marginTop':'0px'
				}); 
			  }
		};
		*/
		
		// LAYOUT & SORT
		
		$("layout").getElements("li").each(function(elem){
			elem.addEvents({
				click:function(elem){
					$("layout").getElements("li").removeClass("on");
					$("layout").getElements("li").fade(.5);
					$(this).fade(1);
					$(this).addClass("on");
					$("itemBrowser").removeClass("display_list");
					$("itemBrowser").removeClass("display_grid");
					$("itemBrowser").addClass("display_"+$(this).id);
					ajax_execute("","itemBrowserLayout","layout="+$(this).id,"false",0);
				}
			})
		});
		$("order").getElements("li").each(function(elem){
			elem.addEvents({
				click:function(elem){
					$("order").getElements("li").removeClass("on");
					$("order").getElements("li").fade(.5);
					$(this).fade(1);
					$(this).addClass("on");
					ajax_execute("itemBrowser","itemBrowser","s=0&order="+$(this).id,"false",0);
				}
			})
		});
		
		/* SEARCH */
		
		$("search").addEvents({
			"click":function(){
				$("searchContainer").addClass("searchon");
			},
			"keyup":function(){
				if (this.value!=""){
					$("searchClose").setStyle("display","block");
				}
				else
					$("searchClose").setStyle("display","none");
				$("browseCategories").getElements("a").removeClass("on");
					
				ajax_execute("itemBrowser","itemBrowser","parameter="+this.value+"&type=Search&s=0","false",0);
			}
		});
		$("searchClose").addEvents({
			"click":function(){
				$("search").value="";
				$("search").focus();
				$("searchClose").setStyle("display","none");
				ajax_execute("itemBrowser","itemBrowser","parameter=&type=Search&s=0","true",0);
			}
		});
		if ($('search'))
		myovertext = new OverText('search',{
			poll:true,
			positionOptions: {
				offset: {
					x: -1,
					y: 0
				}
			}
		});
		
		// CATEGORIES
		
		$("browseCategories").getElements("ul").each(function(elem){
			new Fx.Reveal($(elem), {mode: "vertical"});
			elem.set("reveal", {duration: 200, transition: Fx.Transitions.Sine.easeOut, transitionOpacity:true});
			elem.toggle().hide(); //hide it
		});
		
		$("browseCategories").getElements("span.arrow").addEvent("click",function(){
			var myDiv=this.getParent("li").getElement("ul");
			if (myDiv){
				if (parseInt(myDiv.getStyle("height"))>10){
					this.removeClass("on");
					myDiv.dissolve();
				}
				else {
					this.addClass("on");
					myDiv.reveal();
				}
			}
		});
		$("browseCategories").getElements("a").addEvent("click",function(){
			
			// EXPAND/COLLAPSE
			var myDiv=this.getParent("li").getElement("ul");
			var myArrow=this.getParent("li").getElement("span.arrow");
			
			if (myDiv){
				if (parseInt(myDiv.getStyle("height"))>10){
					myArrow.removeClass("on");
					myDiv.dissolve();
				}
				else {
					myArrow.addClass("on");
					myDiv.reveal();
				}
			}
			
			// LINK BUTTON
			$("browseCategories").getElements("a").removeClass("on");
			this.addClass("on");
			$("searchContainer").removeClass("searchon");
			$("search").value="";
			$("searchClose").setStyle("display","none");
			ajax_execute("itemBrowser","itemBrowser","s=0&type=Category&parameter="+this.get("alt"),"true",0);
		});
		
		// FILTER BY COMPANY
		
		$("browseCompanies").getElements("li").addEvent("click",function(elem){
			var checkBox=this.getElement("span.check");
			var categoryName=this.getProperty("alt");
			
			if (checkBox.getElement("span")){
				filterCompanies.erase(categoryName);
				checkBox.getElement("span").destroy();
			}
			else {
				filterCompanies.include(categoryName);
				var check = new Element("span").inject(checkBox,"top");
			}
			ajax_execute("itemBrowser","itemBrowser","s=0&filter:company="+filterCompanies.join(","),"false",0);
		});
	}
});
function clearFilter(func){
	$("browseCompanies").getElements("span.check").each(function(elem){
		if (elem.getElement("span"))
		elem.getElement("span").destroy();
	});
	filterCompanies.empty();
	ajax_execute(func,func,"s=0&filter:company=","false",0);
}
function checkFilter(func){
	$("browseCompanies").getElements("li").each(function(elem){
		var checkBox=elem.getElement("span.check");
		var categoryName=elem.getProperty("alt");
			
		if (!checkBox.getElement("span"))
		var check = new Element("span").inject(checkBox,"top");
		filterCompanies.include(categoryName);
	});
	ajax_execute(func,func,"s=0&filter:company="+filterCompanies.join(","),"false",0);
}
function expandAll(){
	$("browseCategories").getElements("span.arrow").addClass("on");
	$("browseCategories").getElements("ul").reveal();
}
function collapseAll(){
	$("browseCategories").getElements("span.arrow").removeClass("on");
	$("browseCategories").getElements("ul").dissolve();
}

var currpage;
var numpages;
var limit;
var s;
function browseNav(currpage,numpages,limit,s,func) {
	$('browseNav').empty();
	
	var navLeft = new Element('div', {
		events: {
			'click':function(){
				if (currpage!=1)
				ajax_execute(func,func,"s="+(limit*(currpage-2)),'true',0);
			}
		}
	}).addClass('arrowL').addClass('arrow').inject($('browseNav'),'bottom');
	var span = new Element('span').inject(navLeft,'top');
	
	if (currpage==1) {
		navLeft.addClass('disabled');
	}
	
	for (var i=1;i<numpages+1;i++){
		var navNum = new Element('div', {
			events: {
				'click':function(){
					ajax_execute(func,func,"s="+(limit*(this.id-1)),'true',0);
				}
			}
		}).appendText(i).inject($('browseNav'),'bottom');
		navNum.set('id',i);
		if (i==currpage) navNum.addClass('on');
	}
	
	var navRight = new Element('div', {
		events: {
			'click':function(){
				if (currpage!=numpages)
				ajax_execute(func,func,"s="+(limit*(currpage)),'true',0);
			}
		}
	}).addClass('arrowR').addClass('arrow').inject($('browseNav'),'bottom');
	var span = new Element('span').inject(navRight,'top');
	
	if (currpage==numpages) {
		navRight.addClass('disabled');
	}
	if (numpages==0 || numpages==1) $('browseNav').setStyle('display','none');
	else $('browseNav').setStyle('display','block');
	
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
SPONSOR SCROLLBAR
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

function scrollInitiate(){
	if ($("itemBrowser").hasClass('display_grid')){
		myProducts = new ScrollBar('sponsorBrowseContainer', 'bar', 'knob', {
			offset: -1,
			scroll: { transition: 'sine:out',duration:300},
			knob: { transition: 'sine:out',duration:200}
		});
	}
	else if ($("itemBrowser").hasClass('display_list')){
		myProducts = new ScrollBar('sponsorBrowseContainer', 'bar', 'knob', {
			offset: -1,
			mode: 'vertical',
			scroll: { transition: 'sine:out',duration:300},
			knob: { transition: 'sine:out',duration:200}
		});
	}
	
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
ITEM BROWSER NAVIGATION - NEWS
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

window.addEvent('domready',function() {
	if (page=='news' && secondpage==''){
		
		/* SEARCH */
		
		$("search").addEvents({
			"click":function(){
				$("searchContainer").addClass("searchon");
			},
			"keyup":function(){
				if (this.value!=""){
					$("searchClose").setStyle("display","block");
				}
				else
					$("searchClose").setStyle("display","none");
				$("browseCategories").getElements("a").removeClass("on");
					
				ajax_execute("newsBrowser","newsBrowser","parameter="+this.value+"&type=search&s=0","false",0);
			}
		});
		$("searchClose").addEvents({
			"click":function(){
				$("search").value="";
				$("search").focus();
				$("searchClose").setStyle("display","none");
				ajax_execute("newsBrowser","newsBrowser","parameter=&type=search&s=0","true",0);
			}
		});
		if ($('search'))
		myovertext = new OverText('search',{
			poll:true,
			positionOptions: {
				offset: {
					x: -1,
					y: 0
				}
			}
		});
		
		// CATEGORIES
		
		$("browseCategories").getElements("a").addEvent("click",function(){
			$("browseCategories").getElements("a").removeClass("on");
			this.addClass("on");
			$("searchContainer").removeClass("searchon");
			$("search").value="";
			$("searchClose").setStyle("display","none");
			ajax_execute("newsBrowser","newsBrowser","s=0&type=category&parameter="+this.get("alt"),"true",0);
		});
		
		// FILTER BY COMPANY
		
		$("browseCompanies").getElements("li").addEvent("click",function(elem){
			var checkBox=this.getElement("span.check");
			var categoryName=this.getProperty("alt");
			
			if (checkBox.getElement("span")){
				filterCompanies.erase(categoryName);
				checkBox.getElement("span").destroy();
			}
			else {
				filterCompanies.include(categoryName);
				var check = new Element("span").inject(checkBox,"top");
			}
			ajax_execute("newsBrowser","newsBrowser","s=0&filter:company="+filterCompanies.join(","),"false",0);
		});
	}
});



	
/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
NEWS SPEC
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/


window.addEvent('domready',function() {
	if (page=='news' && secondpage!=''){
		revealSidebox();
	}
});



/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
PRODUCT SPEC
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var question_form=null;
window.addEvent('domready',function() {
	if (page=='products' && secondpage!=''){
		$('videoGalleryContainer').getElements('span').setStyle('display','block');
		$("wrapper").setStyle('background','url('+uriDir+'_media/images/spec_bg.gif) repeat-y #FFF right');
		
		revealSidebox();
		
		question_form = new FormCheck('form_question',{
			submitByAjax:true,
			submit:false,
			ajaxEvalScripts:true,
			onAjaxRequest:function(){
				$('sendQuestionButton').setStyle('opacity','.2');
				$('sendQuestionButton').set('html','SENDING...');
				question_form.options.submitByAjax=false;
			},
			onAjaxSuccess:function(){
				$('sendQuestionButton').setStyle('opacity','1');
				$('sendQuestionButton').set('html','SEND MESSAGE');
				$('commentForm').value='';
				$('commentSubject').value='';
				question_form.options.submitByAjax=true;
			}
		});
	}
});

function revealSidebox(){
	// HIDE
	$$("ul.sideBoxItems").each(function(elem){
		new Fx.Reveal($(elem), {mode: "vertical"});
		elem.set("reveal", {duration: 200, transition: Fx.Transitions.Sine.easeOut, transitionOpacity:true});
	});
	$("sideBoxInner").getElements('div.title').addEvent('click',function(){
		if (this.hasClass('closed')){
			this.getNext('ul').reveal();
			this.removeClass('closed');
		}
		else {
			this.getNext('ul').dissolve();
			this.addClass('closed');
		}
	});
}


/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
PRODUCT GALLERY
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/
function setFlow(videoID,dir){
	dir='../../../';
	myPlayer[videoID]=flowplayer("video_"+videoID, dir+"_media/js/flowplayer/flowplayer.commercial-3.2.7.swf", {
		// change the default controlbar to tube
		plugins: {
			controls: {
				url: dir+"_media/js/flowplayer/flowplayer.controls-3.2.5.swf"
			},
			gatracker: {
				url: dir+"_media/js/flowplayer/flowplayer.analytics-3.2.2.swf",
				
				// track all possible events. By default only Start and Stop 
				// are tracked with their corresponding playhead time.
				events: {
					all: true,
					finish: 'Finish',
					start: 'Start'
				},
				debug: false,
				accountId: "UA-10484870-1" // your Google Analytics id here
			},
			// the RTMP plugin
			rtmp: {
				url: dir+"_media/js/flowplayer/flowplayer.rtmp-3.2.3.swf",
				
				// netConnectionUrl has our CloudFront domain name + "cfx/st"
				netConnectionUrl: "rtmp://sceij2evxoml.cloudfront.net/cfx/st"
			}
			//pseudo: { url: dir+"_media/js/flowplayer/flowplayer.pseudostreaming-3.2.7.swf" }

		},
		canvas: {
		   backgroundColor: "#000",
		   backgroundGradient: "none",
			border:"2px solid #000"
		},
		screen: {
			
		   backgroundColor: "#000",
		   backgroundGradient: "none"
		},
		accelerated: true,
		clip: {
			provider: "rtmp",
			autoPlay: true,
			eventCategory: "Product Videos",
			eventLabel: "video_"+videoID,
			scaling: "fit"
		}
		
	}).ipad({ simulateiDevice: false});
	
}
var timeoutImg=null;
function activateThumbnails(){
            
	var timeoutVid;
	var printCaption;
	var imageResize = $('image_wrap');
		
	// PHOTO
	
 	// SET CLICK OPTIONS
	$$("#items div").addEvent('click',function() {
		
		// ADD WHEEL
		//$('image_wrap').setStyle('background','url("'+uriDir+'_media/images/loader.gif")  no-repeat center');
		
		// TURN OFF VIDEO AND CAPTION
		$("video").setStyle('display','none');
		
		//$('captionContent').empty();
		if (myPlayer[myPlayer_current] && myPlayer[myPlayer_current].playerTypeGlobal=='html5') 
			myPlayer[myPlayer_current].pause();
		
		printCaption = $(this).getAttribute("name");
		
		// RESIZE DIV AND ADD CAPTION
		var fx = new Fx.Tween(imageResize, {
			duration: 200,
			property: 'height',
			link: 'chain'
		  });
		fx.start(296).chain(function(){
			// SET CAPTION
			//$('captionContent').set("html",printCaption);
			//if (printCaption!='') {
				//var myFx = new Fx.Tween("caption");
				//myFx.set('opacity','0');
				////$('caption').setStyle('display','');
				//myFx.start('opacity','1');
			//}
		});
		var myFx = new Fx.Tween("image_wrap");
		myFx.set('opacity','.5');
		
		// change image
		var url = $(this).getAttribute("alt");
		// DO NOT TURN OFF IMAGE WHEN PAGE FIRST LOADS
		var newImage=$("image").getElement("img");
		$('image').getElement('img').set('src',url);
		
		// WHEN IMAGE LOADS...
		newImage.addEvent('load', function() {
			$('image').getElement('img').setStyle('display','block');
			// ADD WHEEL
			$('image_wrap').setStyle('background','none');
		});
			myFx.start('opacity','1');
		
		// TURN ON IMAGE DIV
		timeoutImg=setTimeout("$('image').setStyle('display','block');",100);
		
		// DISABLE THUMBNAILS
		$('itemsVid').getElements('div').removeClass('active');
		$('items').getElements('div').removeClass('active');
		
		this.addClass('active');
	});
	

	// SET CLICK OPTIONS
	$$("#itemsVid div").addEvent('click',function() {
		
		// ADD WHEEL
		$('image_wrap').setStyle('background','url("'+uriDir+'_media/images/loader.gif")  no-repeat center');
		
		if (flashEnabled==false && ismobile==false){
			alert('Please upgrade your flash player.');
		}
		else {
			// TURN OFF PHOTO AND CAPTION. ALSO TURN OFF OTHER VIDEOS
			$("video").getElements("a").setStyle('display','none');
			$('image').setStyle('display','none');
			
			//if (myPlayer[myPlayer_current] && myPlayer[myPlayer_current].playerTypeGlobal=='html5') 
			//	myPlayer[myPlayer_current].pause();
			//$('image').setStyle('border','#000 solid 1px');
			//$('caption').setStyle('display','none');
			//$('captionContent').empty();
			
			// TURN ON VIDEO DIV
			timeoutVid=setTimeout("$('videoGalleryContainer').setStyle('display','');$('video').setStyle('display','');",400);
			
			// RESIZE DIV AND ADD CAPTION
			var newHeight=parseInt($(this).getAttribute("id"));
			var tempID=$(this).getAttribute("alt");
			divID='video_'+tempID;
			printCaption = $(this).getAttribute("name");
			var fx = new Fx.Tween(imageResize, {
				duration: 200,
				property: 'height',
				link: 'chain'
			  });
			fx.start(newHeight+20).chain(function(){
				document.id('video').setStyle('height',newHeight);
				// TURN ON CORRECT VIDEO
				document.id(divID).setStyle('display','block');
				//myPlayer[tempID].play();
				// REMOVE WHEEL
				$('image_wrap').setStyle('background','none');
			});
			myPlayer_current=$(this).getAttribute("alt");
			
			// DISABLE THUMBNAILS
			$('itemsVid').getElements('div').removeClass('active');
			$('items').getElements('div').removeClass('active');
			
			this.addClass('active');
		}
	});
	
// BROWSE WINDOWS

	// PREPARE ARROWS
	if ($('browsable').getElements('div').length>4)
		$('prodPhotos').getElements('a.nextPage').removeClass('disabled');
	
	if ($('browsableVid').getElements('div').length>4)
		$('prodVideos').getElements('a.nextPage').removeClass('disabled');
	
	// ADD ARROW CLICKS
		// PHOTOS
		var scrollSetPhotos=0;
		var myFxPhotos = new Fx.Tween($('prodPhotos').getElement('div.items'), {
			duration: '200',
			transition: Fx.Transitions.Quad.easeInOut,
			link: 'cancel',
			property: 'left'
		});
		$('prodPhotos').getElements('a.nextPage').addEvent('click',function(event){
			var maxScroll=(($('prodPhotos').getElement('div.items').getElements("div").length-3)*74)*(-1);
			if (scrollSetPhotos!=maxScroll){ // CAN STILL SCROLL
				myFxPhotos.start(scrollSetPhotos,scrollSetPhotos-74);
				scrollSetPhotos=scrollSetPhotos-74;
			} // NO MORE SCROLL
			if (scrollSetPhotos==maxScroll)
				this.addClass('disabled');
			else
				this.removeClass('disabled');
			$('prodPhotos').getElements('a.prevPage').removeClass('disabled');
		});
		$('prodPhotos').getElements('a.prevPage').addEvent('click',function(event){
			if (scrollSetPhotos!=0){ // CAN STILL SCROLL
				myFxPhotos.start(scrollSetPhotos,scrollSetPhotos+74);
				scrollSetPhotos=scrollSetPhotos+74;
			} // NO MORE SCROLL
			if (scrollSetPhotos==0)
				this.addClass('disabled');
			else
				this.removeClass('disabled');
			$('prodPhotos').getElements('a.nextPage').removeClass('disabled');
		});
		
		// VIDEOS 
		var scrollSetVideos=0;
		var myFxVideos = new Fx.Tween($('prodVideos').getElement('div.items'), {
			duration: '200',
			transition: Fx.Transitions.Quad.easeInOut,
			link: 'cancel',
			property: 'left'
		});
		$('prodVideos').getElements('a.nextPage').addEvent('click',function(event){
			var maxScroll=(($('prodVideos').getElement('div.items').getElements("div").length-3)*74)*(-1);
			if (scrollSetVideos!=maxScroll){ // CAN STILL SCROLL
				myFxVideos.start(scrollSetVideos,scrollSetVideos-74);
				scrollSetVideos=scrollSetVideos-74;
			} // NO MORE SCROLL
			if (scrollSetVideos==maxScroll)
				this.addClass('disabled');
			else
				this.removeClass('disabled');
			$('prodVideos').getElements('a.prevPage').removeClass('disabled');
		});
		$('prodVideos').getElements('a.prevPage').addEvent('click',function(event){
			if (scrollSetVideos!=0){ // CAN STILL SCROLL
				myFxVideos.start(scrollSetVideos,scrollSetVideos+74);
				scrollSetVideos=scrollSetVideos+74;
			} // NO MORE SCROLL
			if (scrollSetVideos==0)
				this.addClass('disabled');
			else
				this.removeClass('disabled');
			$('prodVideos').getElements('a.nextPage').removeClass('disabled');
		});
	
};


/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
UPLOAD FILES VIA IFRAME
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var iFrameFormRequest = new Class({

	Implements: [Options, Events],

	options: { /*
		onRequest: function(){},
		onComplete: function(data){},
		onFailure: function(){}, */
		eventName: 'submit'
	},

	initialize: function(form, options){
		this.setOptions(options);
		var frameId = this.frameId = String.uniqueID();
		var loading = false;

		this.form = document.id(form);

		this.formEvent = function(){
			loading = true;
			this.fireEvent('request');
		}.bind(this);

		this.iframe = new IFrame({
			name: frameId,
			styles: {
				display: 'none'
			},
			src: 'about:blank',
			events: {
				load: function(){
					if (loading){
						var doc = this.iframe.contentWindow.document;
						if (doc && doc.location.href != 'about:blank'){
							this.fireEvent('complete', doc.body.innerHTML);
						} else {
							this.fireEvent('failure');
						}
						loading = false;
					}
				}.bind(this)
			}
		}).inject(document.body);

		this.attach();
	},

	send: function(){
		this.form.submit();
	},

	attach: function(){
		this.target = this.form.get('target');
		this.form.set('target', this.frameId)
			.addEvent(this.options.eventName, this.formEvent);
	},

	detach: function(){
		this.form.set('target', this.target)
			.removeEvent(this.options.eventName, this.formEvent);
	},

	toElement: function(){
		return this.iframe;
	}

});

Element.implement('iFrameFormRequest', function(options){
	this.store('iFrameFormRequest', new iFrameFormRequest(this, options));
	return this;
});


/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
SHARE - EMAIL
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

function shareEmail(){
	if (!$('shareContainer')){
		var shareContainer=new Element('div',{
			'id':'shareContainer'
		}).inject(document.body);
		shareContainer.setStyle('opacity',0);
		shareContainer.position({
			relativeTo: $('share'),
			position: 'centerBottom',
			edge: 'centerBottom',
			offset: {x:0,y:40}
		});
		// ADD CONTENTS
		shareContainer.set('html','<div class=carrat></div><input name=email id=emailInput class=smallForm alt="Email Address"> <a href="javascript:shareSubmit()"></a>');
		// OVERTEXT
		var emailInput=new OverText('emailInput',{
			positionOptions: {
				offset: {
					x: 5,
					y: 5
				}
			},
			labelClass: 'companySearch_overtext'
		});
		// TURN ON
		var myFx = new Fx.Tween('shareContainer', {property: 'opacity',duration:'100'});
		myFx.start(0,1).chain(function(){
			//window.addEvent('click',shareClose);
		});
		
	}
	else {
		shareClose();
	}
}
function shareSubmit(){
	var email=$('emailInput').value;
	if (email==''){
		alert('Please enter an email address');
	}
	else {
		$('shareContainer').set('html','<span><div class=loader4></div>Sending...</span>');
		setTimeout("ajax_execute('shareContainer','sharePage','email="+email+"&name="+encodeURIComponent($('pageName').get('html'))+"&url="+window.location.pathname+"','');",500);
	}
}
function shareClose(){
	var myFx = new Fx.Tween('shareContainer', {property: 'opacity',duration:'100'});
	myFx.start(1,0).chain(function(){
		//window.removeEvent('click',shareClose);
		if ($("shareContainer"))
		$("shareContainer").destroy();
	});
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
OVERLAY
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var Overlay = new Class({
  
  Implements: [Options,Events],
  
  options:  {
    id: 'overlay',
    color: '#000',
    duration: 500,
    opacity: 0.5,
	identity:0,
    zIndex: 5000/*
    onClick: $empty,
    onClose: $empty,
    onHide: $empty,
    onOpen: $empty,
    onShow: $empty
    */
  },
  
  initialize: function(container,options) {
    this.setOptions(options);
    this.container = document.id(container);
    this.overlay = new Element('div',{
      id: this.options.id,
      opacity: 0,
      styles: {
        position: 'absolute',
        backgroundImage: 'url('+uriDir+'_media/images/overlay.png)',
        left: 0,
        top: 0,
		'vertical-align':'middle',
        'z-index': this.options.zIndex
      },
      events: {
        click: function() {
          this.fireEvent('click');
        }.bind(this)
      }
    }).inject(this.container);
    this.tween = new Fx.Tween(this.overlay,{ 
      duration: this.options.duration,
      link: 'cancel',
      property: 'opacity',
      onStart: function() {
        var size = this.container.getScrollSize();
        this.overlay.setStyles({
          width: size.x,
          height: size.y
        });
		if (this.overlay.getStyle('opacity')=='0'){
			var scroll = $(window).getScroll();
			this.overlay.getElement('div').setStyle('top',scroll.y+150);
		}
      }.bind(this),
      onComplete: function() {
        this.fireEvent(this.overlay.get('opacity') == this.options.opacity ? 'show' : 'hide');
		if (this.overlay.get('opacity') != this.options.opacity) this.overlay.setStyle('visibility','hidden');
      }.bind(this)
    });
  },
  open: function() {
    this.fireEvent('open');
	this.overlay.setStyle('visibility','visible');
	if (Browser.name=='ie' && (Browser.version=='7' || Browser.version=='8')){
        var size = this.container.getScrollSize();
        this.overlay.setStyles({
          width: size.x,
          height: size.y
        });
		this.overlay.setStyle('opacity','1');
	}
	else
   	 this.tween.start(this.options.opacity);
  },
  close: function() {
    this.fireEvent('close');
	if (Browser.name=='ie' && (Browser.version=='7' || Browser.version=='8')){
		this.overlay.setStyle('opacity','0');
		this.overlay.setStyle('visibility','hidden');
	}
	else
   	 this.tween.start(0);
  }
});

var olay=new Array();
var lock=0;
function createOverlay(id,title){
	var element=$(id);
	
	// ONLY CREATE OVERLAY IF DOES NOT ALREADY EXIST
	if (!$('overlay'+id)){
		
		olay[id] = new Overlay(document.body, { 
			duration: 200,
			opacity:1,
			identity:id,
			id:'overlay'+id,
			onClick: function() { 
				if (lock==0) 
				olay[id].close();
			}
		});	
		
		// ADD CONTAINER
		var overlayContainer=new Element('div',{'class':'overlayContent'}).addEvent('mouseenter',function(){lock=1}).addEvent('mouseleave',function(){lock=0}).inject($('overlay'+id),'top');
		// ADD TITLE
		var overlayTitle=new Element('div',{'class':'title'}).appendText(title).inject(overlayContainer,'top');
		// ADD CONTENT TO CONTAINER
		element.inject(olay[id].overlay.getElement('div'),'bottom').setStyle('display','block');
		
		// ACTIVATE CHECKBOX
		checkBoxOn(olay[id].overlay);
		
		// ACTIVATE BUTTONS
		if (element.getElementById("accept"))
		element.getElementById("accept").addEvent("click",accept);
	
	}
	
	// OPEN DIALOG
	olay[id].open();
	
}
// Make buttons work
function checkBoxOn(element){
	
	// ACTIVATE CHECKBOX IF EXISTS
	var checkBox=element.getElementById('overlayCheckbox');
	
	if (checkBox){
		checkBox.addEvent('click',function(){
			if (this.getElement("span")){
				this.getElement("input").set("value","");
				this.getElement("span").destroy();
			}
			else {
				this.getElement("input").set("value","true");
				var check = new Element("span").inject(this,"top");
			}
		});
	}
}
function accept(){
	var mainDiv=$(this).getParent('div');
	var checkStatus=mainDiv.getElementById('overlayCheckbox').getElement('input');
	// if box checked, do this
	if (checkStatus.value=='true'){
		// disable button
		$(this).removeEvent("click",accept);
		// add loading icon
		mainDiv.getElement('span#dialog_loading').setStyle("display","inline-block");
		// hide status
		$('dialogStatus').set('html','');
		// execute
		// if "need help" box
		if (mainDiv.get('id')=='needHelp' || mainDiv.get('id')=='needHelpStatus')
			ajax_execute(mainDiv.get('id'),"needHelp","id="+mainDiv.get('id'));
	}
	// if box not checked, error
	else {
		mainDiv.getElementById('overlayCheckbox').setStyle('border','#ff0000 solid 1px');
		mainDiv.getElementById('dialogStatus').set('html','Please check the box to agree to the terms.');
	}
	
}

/*
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
CONTACT US
 -	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
*/

var contact_form=null;
window.addEvent('domready',function() {
	if (section=='contact-us'){
		contact_form = new FormCheck('contact_form',{
			submitByAjax:true,
			submit:false,
			ajaxEvalScripts:true,
			onAjaxRequest:function(){
				$('contact_loading').setStyle('display','');
				contact_form.options.submitByAjax=false;
			},
			onAjaxSuccess:function(){
				$('contact_loading').setStyle('display','none');
				$('contact_form').reset();
				contact_form.options.submitByAjax=true;
			}
		});
	}
});
