// #831ce9
// #ff4a21

var theTopic='default';
var colors = new Array();
colors['default']=[ 'rgb(153,237,237)', 'rgb(258,128,129)', 'blue'];
colors['art']= ['#ffcc99', '#ffff99', '#00ffcc']; 
colors[ 'diary'] = [ '#886262', '#000000', '#efe1c1 '];
colors['vita'] = [ '#ff0000', '#ffff00', '#0000ff' ];
colors['pub'] = [ '#f27f84', '#7d93c4', '#f27eeb' ];
colors['press'] = [ '#f16d54', '#e9ff83', '#b5ecff' ];
colors['shop'] = [ '#e3e7ea', '#7ff4da', '#f893b5' ];
colors['supernice'] = [ '#f893b5', '#7ff4da', '#e3e7ea' ];

var theBorderWidth=15;
var xmasWidth = new Array();
xmasWidth[1]=22;
xmasWidth[2]=54;
xmasWidth[3]=87;
xmasWidth[4]=128;
xmasWidth[5]=160;
xmasWidth[6]=191;
xmasWidth[7]=220;
xmasWidth[8]=250;
xmasWidth[9]=281;
xmasWidth[10]=322;
xmasWidth[11]=359;
xmasWidth[12]=401;
xmasWidth[13]=444;
xmasWidth[14]=488;
xmasWidth[15]=530;
xmasWidth[16]=571;
xmasWidth[17]=610;
xmasWidth[18]=658;
xmasWidth[19]=699;
xmasWidth[20]=750;
xmasWidth[21]=792;
xmasWidth[22]=844;
xmasWidth[23]=897;
xmasWidth[24]=951;

function frameIt()
{
var x = myViewport();
var h = x.height; // $('content').getHeight()+6* theBorderWidth;
var w = x.width ;

$('content').wrap( 'div' , { 'id': 'box3' } );
$('box3').wrap( 'div' , { 'id': 'box2' } );
$('box2').wrap( 'div' , { 'id': 'box1' } );

var params = getUrlVars();
if ( params['xmas']==1) {
	var t = h-89;
	var l = w/2-847/2;
	var day = params['xmasday'];
     	if (day<1 || day>24) day=1;
	var newI = new Element( 'img' );
	newI.src ='../digitsGray.png';
	newI.style.position = 'absolute';
	newI.style.top = t + 'px';
	newI.style.left = l+'px';
	newI.style.zIndex = 999;
	Element.insert( $('box1'), {'after':newI} ); 
	// above a div with the colored img
	var newBox = new Element( 'div' );
	newBox.style.position = 'absolute';
	newBox.style.top = t +'px';
	newBox.style.left = l +'px';
	newBox.style.width = xmasWidth[day]+'px';
	newBox.style.zIndex = 1000;
	newBox.style.overflow = 'hidden';
	newBox.innerHTML = '<img src="../digits.png">';
	Element.insert( $('box1'), {'after':newBox} ); 

}
myResize2();
}



function getUrlVars(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++){
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

var vpOverrideWidth=0;
var vpOverrideHeight=0;

function myViewport()
{

var e = window , a = 'inner';
if ( !( 'innerWidth' in window ) ) {
	a = 'client';
	e = document.documentElement || document.body;
}
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }
	
var x = document.viewport.getDimensions();
	if (x.height==0) {
		alert(0);
		x=getViewport();
	}

	if (vpOverrideWidth) {
		x.width=vpOverrideWidth;
	}
	if (vpOverrideHeight) {
		x.height=vpOverrideHeight;
	}
	x .height = $('content').getHeight();
	return x;
}

function myResize2()
{
	var x = myViewport();
	var h = x.height; // $('content').getHeight()+6* theBorderWidth;
	var w = x.width ;
	$('box1').setStyle('border-style: solid');
	$('box1').setStyle('border-width:'+theBorderWidth+'px');
	$('box1').style.width = w-theBorderWidth*2+'px';
	$('box1').style.height = h-theBorderWidth*2+'px';
	$('box1').setStyle('border-color:'+colors[theTopic][2]);
	
	$('box2').setStyle('border-style: solid');
	$('box2').setStyle('border-width:'+theBorderWidth+'px');
	$('box2').style.width = w-theBorderWidth*4+'px';
	$('box2').style.height = h-theBorderWidth*4+'px';
	$('box2').setStyle('border-color:'+colors[theTopic][1]);

	$('box3').setStyle('border-style: solid');
	$('box3').setStyle('border-width:'+theBorderWidth+'px');
	$('box3').style.width = w-theBorderWidth*6+'px';
	$('box3').style.height = h-theBorderWidth*6+'px';
	$('box3').setStyle('border-color:'+colors[theTopic][0]);

	var x2 = theBorderWidth*3 ;
	$('content').style.top = theBorderWidth*3+'px';
	$('content').style.left = x2+'px';
	$('content').style.width = w-theBorderWidth*6+'px';
	$('content').style.height = x.height-theBorderWidth*6+'px';
}


