/***********************************************
* Ocean-7 Development©, built upon minimum base - Amazon style Drop-in content box- © Dynamic Drive DHTML code library (www.dynamicdrive.com) 
***********************************************/
var dropboxminwidth = 662
var dropboxleft=0 //set left position of box (in px)
var dropboxtop=0 //set top position of box (in px)
var dropboxwidth=dropboxminwidth
var dropspeed=6 //set speed of drop animation (larger=faster)
var dropstart=null;

var docWidth, docHeight;
var expanded=0;
var totalSecs = 5;
var crossboxcover;
var x, y, compbox, boxleft, boxwidth, boxtop, boxheight;

var ie=document.all
var dom=document.getElementById
function initboxv2(){
	if (!dom&&!ie){
		return
	}
	crossboxcover=(dom)?document.getElementById("secboxcover") : document.all.secboxcover
	crossbox=(dom)?document.getElementById("secbox"): document.all.secbox
	crossbox.height=crossbox.offsetHeight
	crossboxcover.style.height=parseInt(crossbox.height)+"px"
	crossbox.style.top=crossbox.height*(-1)+"px"
	crossboxcover.style.left=dropboxleft+"px"
	crossboxcover.style.top=dropboxtop+"px"
	dropboxwidth=(ie)?parseInt(document.body.offsetWidth-dropboxleft-25):parseInt(document.width-dropboxleft-25);
	if(dropboxwidth < dropboxminwidth){
		dropboxwidth = dropboxminwidth;
	}
	crossboxcover.style.width=dropboxwidth+"px";
	crossboxcover.style.visibility=(dom||ie)? "visible" : "show"
	dropstart=setInterval("dropinv2()",50)
}

function dropinv2(){
	if (parseInt(crossbox.style.top)<0){
		crossboxcover.style.top=dropboxtop+"px"
		crossbox.style.top=parseInt(crossbox.style.top)+dropspeed+"px"
	}
	else{
		clearInterval(dropstart)
		crossbox.style.top=0
	}
}

function dismissboxv2(){
	if (window.dropstart) clearInterval(dropstart)
	crossboxcover.style.visibility="hidden"
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function setSwipePos(){
	var pos = findPos(cb_getElement('droppoint'));
	if(pos != null){
		dropboxleft=pos[0];
		dropboxtop=pos[1];
	}
}

function reposSwipe(){
	crossboxcover=(dom)?document.getElementById("secboxcover") : document.all.secboxcover;
	setSwipePos();
	crossboxcover.style.left=dropboxleft+"px"
	crossboxcover.style.top=dropboxtop+"px"
	dropboxwidth=(ie)?parseInt(document.body.offsetWidth-dropboxleft):parseInt(document.width-dropboxleft);
	if(dropboxwidth < dropboxminwidth){
		dropboxwidth = dropboxminwidth;
	}
	crossboxcover.style.width=dropboxwidth+"px";
}

function setDropText(dropblock){
	cb_getElement('secbox').innerHTML = cb_getElement(dropblock).innerHTML;
}

function swipeface(num, txtname){
	if(expanded == num){
		return;
	}
	if(dropstart != null){
		clearInterval(dropstart);
	}
	setSwipePos();
	setDropText(txtname); 
	swapface(num);  
	initboxv2(); 
	expanded = num;
	return false;
}

function swapface(num){
	document.images['secimg'+num].src = eval('imgOn'+num+'.src');
	for(i=1; i<=totalSecs; i++){
		if(i!=num){
			unswapface(i);
		}
	}
}
function unswapface(num){
	document.images['secimg'+num].src = eval('imgOff'+num+'.src');
	cb_getElementStyle("secface"+num).color="#7B7C7C";
}

function checkSwap(e, num){
	if (!e) var e = window.event;

	if(isWithinBounds(e)){
		return;
	} 
	else {
		unswapface(num);
	}
}

function checkHideComp(e, num){
	if (!e) var e = window.event;
	if(isWithinBounds(e)){
		return;
	} 
	else {
		crossboxcover.style.visibility="hidden";
		expanded = 0;
	}
	unswapface(num);
}

function isWithinBounds(e){
	x = e.clientX;
	y = e.clientY;
	x += document.body.scrollLeft;
 	y += document.body.scrollTop;
	
	compbox = cb_getElement("secboxcover");
	boxleft = compbox.style.left;
	boxwidth = compbox.style.width;
	boxtop = compbox.style.top;
	boxheight = compbox.style.height;
	
	boxleft = parseInt(boxleft.substring(0, boxleft.indexOf("px")));
	boxwidth = parseInt(boxwidth.substring(0, boxwidth.indexOf("px")));
	boxtop = parseInt(boxtop.substring(0, boxtop.indexOf("px")));
	boxheight = parseInt(boxheight.substring(0, boxheight.indexOf("px")));
	boxright = boxleft+boxwidth;
	boxbottom = boxtop+boxheight;

	if(x >= boxleft && x <= boxright && y >= (boxtop-boxheight) && y <= boxbottom){
		return true;
	} 
	//alert("clientX="+e.clientX+"\nclientY="+e.clientY+"\nx="+x+"\ny="+y+"\nboxleft="+boxleft+"\nright="+boxright+"\nboxtop="+parseInt(boxtop-5)+"\nbottom="+boxbottom);
	return false;
}
