var resizeSpeed = 7;	// controls the speed of the image resizing (1=slowest and 10=fastest)
var resizeDuration = (11 - 7) * 0.15;

// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

function boxbox(src, w, h)
{
    hideSelectBoxes();

    var objBody = document.getElementsByTagName("body").item(0);

		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
    // objOverlay.oncontextmenu = function() { endBoxbox(); return false; }
		objBody.appendChild(objOverlay);

		var objBoxbox = document.createElement("div");
		objBoxbox.setAttribute('id','boxbox');
		objBoxbox.style.display = 'none';
    // objBoxbox.oncontextmenu = function() { endBoxbox(); return false; }
		objBody.appendChild(objBoxbox);

    var ObjBoxboxContainer = document.createElement("div");
    ObjBoxboxContainer.id = "boxboxContainer";
		objBoxbox.appendChild(ObjBoxboxContainer);
		
		ObjBoxboxContainer.innerHTML = '<a href="javascript:endBoxbox();"><span>&#160;</span></a>';

    var ObjBoxboxContent = document.createElement("div");
    ObjBoxboxContent.id = "boxboxContent";
    ObjBoxboxContent.style.display = "none";
		ObjBoxboxContainer.appendChild(ObjBoxboxContent);

    var ObjboxboxClose = document.createElement("a");
    ObjboxboxClose.id = "boxboxClose";
    ObjboxboxClose.href = "javascript:endBoxbox();";
		ObjBoxboxContainer.appendChild(ObjboxboxClose);
		
    if (src == '/dyn/timeline.swf') {
  		var ObjboxboxTextonly = document.createElement('a');
  		ObjboxboxTextonly.id = 'boxboxText';
      ObjboxboxTextonly.href = '/textonly_timeline.php';
  		ObjBoxboxContainer.appendChild(ObjboxboxTextonly);
    }

    ObjboxboxClose.innerHTML = '<span>&#160</span>';

		$('boxboxContent').style.display = "none";

     var re = new RegExp("swf$");
     var re2 = new RegExp("php$");
     
     if (src.match(re2)) {
         $('boxboxContent').innerHTML = '<iframe src="'+src+'" width="800" height="600" style="border:none"></iframe>';
         new Effect.ScrollTo('shop');
     } else if(src.match(re)) {
        //$('boxboxContent').innerHTML = '<object style="z-index: 100000; background: red;" type="application/x-shockwave-flash" data="'+src+'" width="'+w+'" height="'+h+'"><param name="movie" value="'+src+'" /></object>';
        //$('boxboxContent').innerHTML = '<object width="'+w+'" height="'+h+'"><param name="movie" value="'+src+'"><embed src="'+src+'" width="'+w+'" height="'+h+'"></embed></object>';

        var flash = new SWFObject(src, "", w, h, "9", "");
        flash.useExpressInstall('/js/so/expressinstall.swf');
        flash.write("boxboxContent");
    } else {
        $('boxboxContent').innerHTML = '<img src="'+src+'" height="'+h+'" width="'+w+'" alt="" />';
    }

    var arrayPageSize = getPageSize();
    $('overlay').style.height = arrayPageSize[1] +"px";
    $('overlay').style.display = "block";
    Element.show('boxbox');

    resize(w, h, '1');

    new Effect.Appear('boxboxContent', { delay: resizeDuration*2.1, duration: 0, from: 1, to: 1.0 });
}

// ---------------------------------------------------

function resize(w, h, q)
{
    var borderSize = 0;
    
    h = h + 7

		// get current height and width
		this.wCur = $('boxboxContainer').offsetWidth;
		this.hCur = $('boxboxContainer').offsetHeight;

		// scalars based on change from old to new
		this.xScale = ((w  + (borderSize * 2)) / this.wCur) * 100;
		this.yScale = ((h  + (borderSize * 2)) / this.hCur) * 100;

		// calculate size difference between new and old image, and resize if necessary
		wDiff = (this.wCur - borderSize * 2) - w;
		hDiff = (this.hCur - borderSize * 2) - h;

    new Effect.Scale('boxboxContainer', this.yScale, {scaleX: false, duration: resizeDuration, queue: q});
    new Effect.Scale('boxboxContainer', this.xScale, {scaleY: false, delay: resizeDuration, duration: resizeDuration, queue: q});
}

function endBoxbox()
{
    Element.hide('boxbox');
    $('overlay').style.display = "none";

    showSelectBoxes();
}


// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------
