window.addEvent('domready', TB_init);



// This is to insure that orphan pages are opened in the main page only
var text = window.location.href;
function delineate(str) {
theleft = str.indexOf("=") + 1;
theright = str.indexOf("&");
return(str.substring(theleft, str.length));
}
url=delineate(text)

function refreshFrame() {
if(mainiframe.location!=url&&url!=location.href)
mainiframe.location.replace(url);
	$('contentHolderLg').style.display="block";
	$('contentHolderSm').style.display="none";
	var framename=$('mainiframe');
	framename.width="100%";
}

// add mainContainer to href elements that have a class of .maincontainer
function TB_init(){
	$$("a.mainContainer").each(function(el){el.onclick=maincontainerLoad});
		
}

function loadConsultantInformation(){
	
	//loadconsultant information into main page by AJAX
	var url = "http://www.2create.ca/app/consultants.asp";
 
	/**
	 * The simple way for an Ajax request, use onRequest/onComplete/onFailure
	 * to do add your own Ajax depended code.
	 */
	new Ajax(url, {
		method: 'get',
		update: $('contentHolderSm')
	}).request();
	$('contentHolderSm').style.display="block";

}

function maincontainerLoad(event) {
	//alert ('event captured');
	var event = new Event(event);
	// stop default behaviour
	event.preventDefault();
	// remove click border
	this.blur();
	// get caption: either title or name attribute
	loadintoIframe('mainiframe',this.href);
	this.onclick=maincontainerLoad;
	return false;
}

function iFrameHeight() {
	//turnoffLoader();
	if(document.getElementById && !(document.all)) {
	h = document.getElementById('mainiframe').contentDocument.body.scrollHeight;
	document.getElementById('mainiframe').height = h;
	document.getElementById('mainiframe').style.height = h+60;
	//alert ('1 '+h);
	
	}
	else if(document.all) {
	h = document.frames('mainiframe').document.body.scrollHeight;
	document.all.mainiframe.height = h;
	document.all.mainiframe.style.height = h;
	//alert ('2');
	}
	
}
//-->


function loadintoIframe(iframeid, url){
if (document.getElementById)
//alert (url);
document.getElementById(iframeid).src=url
	$('contentHolderLg').style.display="block";
	$('contentHolderSm').style.display="none";
	//$('mainiframe').style.display="block";
	
}

//Disable right mouse click Script
var message="To Contact 2 Create Please click on the Contact Button";
///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
//if (e.which==2||e.which==3){
//alert(message);
//return false;
//}
}
}

//if (document.layers){
//document.captureEvents(Event.MOUSEDOWN);
//document.onmousedown=clickNS4;
//}
//else if (document.all&&!document.getElementById){
//document.onmousedown=clickIE4;
//}
//document.oncontextmenu=new Function("alert(message);return false")



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function viewSlideShow(){
	$('leftColumn').tween('opacity', 0);
	$('contentHolderSm').tween('opacity', 0);
	
	var cont=$('contentHolderLg').getStyle('display');
	
	if (cont=='block'){
		createCookie('activeContent','contentHolderLg',1);
		$('contentHolderLg').tween('opacity', 0);
		
	}
	var cont=$('contentHolderSm').getStyle('display');
	
	if (cont=='block'){
	createCookie('activeContent','contentHolderSm',1);
	applyEffects('contentHolderSm',1,1000);
	}
	var cont=$('productDetail').getStyle('display'); 
	
	if (cont=='block'){
	createCookie('activeContent','productDetail',1);
	applyEffects('productDetail',1,1000);
	}

 document.getElementById('viewss').innerHTML="<a id=\"demo2run1\" href=\"#\" 	onclick=\"resumeShopping()\"><img src=\"images/css/BackToSite.png\"></a>";

}

function resumeShopping(){
	applyEffects('leftColumn',2,1000);
	applyEffects('menuHolder',4,500);
	var x = readCookie('activeContent')
	applyEffects(x,2,1000);
document.getElementById('viewss').innerHTML="<a id=\"demo2run1\" href=\"#\" onclick=\"viewSlideShow()\"><img src=\"images/css/viewimages.png\"></a>";
}

function slideshopOver(){
	document.getElementById('viewss').innerHTML="<a id=\"demo2run1\" href=\"#\" onclick=\"startSlideshopOver()\">|&nbsp;&nbsp;RESTART SLIDESHOW</a>&nbsp;&nbsp;|";
}
function startSlideshopOver(){
	var cont1=$('contentHolderSm').getStyle('opacity'); 
	//alert (cont1);
	if (cont1=='1'){
		document.getElementById('viewss').innerHTML="<a id=\"demo2run1\" href=\"#\" onclick=\"viewSlideShow()\">|&nbsp;&nbsp;VIEW IMAGES</a>&nbsp;&nbsp;|";
	}
	else if (cont1=='0'){
	 document.getElementById('viewss').innerHTML="<a id=\"demo2run1\" href=\"#\" 	onclick=\"resumeShopping()\">|&nbsp;&nbsp;BACK TO SITE</a>&nbsp;&nbsp;|";
	}	
	
  restartSlideShow();	
	
}




function applyEffects(divid,effecttpe,howlong) {
//alert("apply activated");
var aEffect = $(divid);
		switch (effecttpe)
		{
		case 1:
		  	 $(divid).tween('opacity', 0);
		  break
		case 2:
		   	$(divid).tween('opacity', 1);
		  break
		  	case 3:
		  	$(divid).tween('opacity', 0);
		  break
		 	case 4:
		   $(divid).tween('opacity', 1);
		  break
		default :  
			$(divid).tween('opacity', 0.5);;
		}
}	

function handleAjaxRequests(effect){
	
	switch (effect) {
		case 0: 
		 //Turn on contentHolderLg turn everything else off
		 //Turn off contentHolderSm
		 //Turn Off productDetail
		document.getElementById('contentHolderSm').style.display = "none";
		document.getElementById('productDetail').style.display = "none";
		document.getElementById('contentHolderLg').style.display = "block";
		//sendRequest(0,url,holder,str,3,0);
		break; 
		case 1: 
		 //Turn off contentHolderLg turn everything else off
		 //Turn off contentHolderSm
		 //Turn On productDetail
		document.getElementById('contentHolderSm').style.display = "none";
		
		//var PDWwidth = document.getElementById('productDetailWhite');
		//var divheight = parseInt(document.getElementById("productDetailWhite").offsetHeight);
		//alert ('Div height is '+divheight);
		document.getElementById('productDetail').style.display = "block";
		//PDWwidth.style.height = divheight  +"px";
		//document.getElementById('productDetailWhite').style.height="800px";
		
		
		document.getElementById('contentHolderLg').style.display = "none";
		//sendRequest(0,url,holder,str,3,0);
		break; 
		
		case 2:
			sendRequest(0,url,holder,str,effect,1,0);
		break;
		case 4:
			VeiwCart();
		break;
		case 5:
			//bodyload only turn everything
			//contentHolderSm on
			//leftColumn on
			startmenu();
			document.getElementById('contentHolderSm').style.display = "block";
			document.getElementById('leftColumn').style.display = "block";
		break;
		case 6:	
		 // This has been to Add to List
		 	sendRequest(0,'viewcart.asp','ILrepeat','action=<%= now()%>',0,4);
			document.getElementById('addtoILbutton').onclick=new Function("handleAjaxRequests(0)");
			document.getElementById('addtoILbutton').style.background= "#006600";
			document.getElementById('addtoILbutton').value= "Return to List";
			
		break;	
		
		case 7: 
		 //view feature Item
		 //Turn on contentHolderSm
		 //Turn On productDetail
		document.getElementById('contentHolderSm').style.display = "block";
		document.getElementById('productDetail').style.display = "none";
		document.getElementById('contentHolderLg').style.display = "none";
		break;
		//sendRequest(0,url,holder,str,3,0);
		case 8:	
			document.getElementById('addtoILbutton').onclick=new Function("handleAjaxRequests(7)");
			document.getElementById('addtoILbutton').style.background= "#006600";
			document.getElementById('addtoILbutton').value= "Back";
		
		break;
		case 9:	
		//load body content
			document.getElementById('contentHolderSm').style.display = "block";
			document.getElementById('leftColumn').style.display = "block";
			document.getElementById('container').style.display = "block";
			
		break;
		
		default:
			sendRequest(0,url,holder,str,effect,1,2);
	//onclick=handleAjaxRequests('productDetails.asp','action=1,itemID=638','productDetailWhite',0)
	}
}


function memberLogin(){
	window.location = "../members/index.asp";
				
}
function getGalleries(){

	var url = "app/loadGalleries.asp";
	 var galleries= $('cg');
	new Ajax(url, {
		method: 'get',
		update: galleries,
		onRequest: function(){
			
		},	
		 onComplete: function(result)
            {
                TB_init(); //add smoothbox capabilities function location smoothbox.js;
            }
	}).request();


}

