var initWidth = document.body.scrollWidth;
var sbDefaultMargin = document.body.style.margin;
var sbDefaultPadding =document.body.style.padding;
var sb_skin_width = 1024;
var sb_skin_heigth = 485;

function add_curtain(curr_height){
	if(curr_height != 'undefined'){
		sb_player_height = curr_height;
	}
	div = document.createElement('div');
	div.style.zIndex = 998;
	div.style.filter = 'alpha(opacity = 40)';
	div.style.opacity = '0.4';
	if (document.all) {
		div.style.position='absolute';
		div.style.height= (document.body.offsetHeight)+'px';
	}else{
		div.style.position='fixed';
		div.style.height = (getDocumentHeight())+'px';
	}
	div.style.width= (getDocumentWidth())+'px';
	div.style.top='0px';
	div.style.left='0px';	
	div.style.backgroundColor='black';
	div.id= 'wizard_curtain';
	
	if(document.getElementById('wizard_curtain') == null){
		document.body.appendChild(div);
	}
	
	resize_curtain(sb_player_height);		
	document.getElementById('sb_com_ads').style.display='none';
	document.getElementById('sb_com_iframe').style.display='none';
	document.getElementById('wizard_curtain').style.display='none';
}
function resize_curtain(sb_player_height){
	var arrayPageSize = getPageSize();
	var size = documentSize();
	//document.getElementById('wizard_curtain').style.width = (arrayPageSize[1])+'px';
	document.getElementById('wizard_curtain').style.width = (size[0])+'px';
	
	if (!document.all) {
		document.getElementById('wizard_curtain').style.height =  (size[1])+'px';
	}
	
	document.getElementById('sb_com_ads').style.width = (document.body.scrollWidth)+'px';
	var total_sb_player_height = parseInt(sb_player_height)+250;	
	document.getElementById('sb_com_ads').style.height = (total_sb_player_height)+'px';
	
	var position = sbScrollPos();
	
	//find viewport width and heigth
	var viewportWidth = 0;
	var viewportHeight = 0;
	if (typeof window.innerWidth != 'undefined') {
		viewportWidth = window.innerWidth;
		viewportHeight = window.innerHeight;
	}else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
	   viewportWidth = document.documentElement.clientWidth;
	   viewportHeight = document.documentElement.clientHeight;
	}else {
		viewportWidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportHeight = document.getElementsByTagName('body')[0].clientHeight;
	}	
	lightboxHeight = parseInt(document.getElementById('sb_com_ads').style.height);
	lightboxPosTop  = parseInt((viewportHeight-lightboxHeight)/2);
	
	if (document.all) {
		sbIframeTop = 105;
	}else {
		sbIframeTop = 125;
	}
	document.getElementById('sb_com_ads').style.top = (parseInt(position)+lightboxPosTop)+'px';
	//document.getElementById('sb_com_iframe').style.top = (parseInt(position)+lightboxPosTop+sbIframeTop)+'px';	
	document.getElementById('sb_com_iframe').style.top = (parseInt(position)+lightboxPosTop)+'px';
	
	
	document.getElementById('sb_close_span').style.top = (parseInt(position)+lightboxPosTop+5)+'px';
	

	if(document.all){
		if(detectBrowserVersion() == 6){
			document.getElementById('wizard_curtain').style.height = (document.documentElement.offsetHeight - 21) + 'px';
			document.getElementById('wizard_curtain').style.width = (document.documentElement.offsetWidth - 20) + 'px';
		}else if(detectBrowserVersion() == 7){
			document.getElementById('wizard_curtain').style.height = (document.documentElement.offsetHeight - 0) + 'px';
			document.getElementById('wizard_curtain').style.width = (document.documentElement.offsetWidth - 0) + 'px';
		}else if(detectBrowserVersion() == 8){
			document.getElementById('wizard_curtain').style.height = (document.documentElement.offsetHeight - 0) + 'px';
			document.getElementById('wizard_curtain').style.width = (document.documentElement.offsetWidth - 22) + 'px';
			document.getElementById('sb_com_ads').style.width = document.getElementById('wizard_curtain').style.width;
		}else {
			document.getElementById('wizard_curtain').style.height = (document.documentElement.offsetHeight - 0) + 'px';
			document.getElementById('wizard_curtain').style.width = (document.documentElement.offsetWidth - 15) + 'px';
		}
		
		var ie_scroll_top = document.documentElement.scrollTop;
		document.getElementById('wizard_curtain').style.marginTop = ie_scroll_top + 'px';
	
	}else{
		document.getElementById('wizard_curtain').style.width = (document.documentElement.offsetWidth - 0) + 'px';
	}
	
	document.getElementById('sb_com_ads').style.width = document.getElementById('wizard_curtain').style.width;
	document.getElementById('sb_iframe_content').style.width = sb_skin_width;
	var iframe_pos_left = parseInt(document.getElementById('sb_com_ads').style.width) - sb_skin_width;
	document.getElementById('sb_com_iframe').style.left = (iframe_pos_left/2) + 'px';
	
	
	
}
function show_curtain(iframe_id){
	hideFlash();
	hideSelectBoxes();
	sbHandleMargins();
	if (document.all) {
		document.getElementById('sb_iframe_content').style.width = (initWidth)+'px';
	}
	var position = sbScrollPos();
	document.getElementById('sb_iframe_content').src = iframe_id;		
	document.getElementById('sb_com_ads').style.display = '';
	document.getElementById('sb_top_div').style.display = '';
	document.getElementById('sb_com_ads').style.left = '0px';
	document.getElementById('sb_com_ads').style.top = (parseInt(position)+80)+'px';
	
	document.getElementById('sb_com_iframe').style.display = '';
	
	var iframe_pos_left = parseInt(document.getElementById('sb_com_ads').style.width) - sb_skin_width;
	document.getElementById('sb_com_iframe').style.left = (iframe_pos_left/2) + 'px';
	document.getElementById('sb_com_iframe').style.top = (parseInt(position)+280)+'px';
	
	document.getElementById('wizard_curtain').style.display='block';
	resize_curtain(sb_player_height);
}
function hide_sb_ads(clear){
	showFlash();
	showSelectBoxes();
	document.getElementById('sb_iframe_content').src = '';
	document.getElementById('sb_com_ads').style.display = 'none';
	document.getElementById('sb_top_div').style.display = 'none';
	document.getElementById('sb_com_iframe').style.display = 'none';
	document.getElementById('wizard_curtain').style.display = 'none';

	document.body.style.padding = sbDefaultPadding;
	document.body.style.margin = sbDefaultMargin;
}
function documentSize(){
	var myWidth = getDocumentWidth();
	var myHeight = getDocumentHeight();
	return [myWidth, myHeight];
}
getDocumentHeight = function(){
	return window.screen.height;
}
getDocumentWidth = function(){
	if (document.body.scrollWidth)
	return document.body.scrollWidth;
	var w = document.documentElement.offsetWidth;
	if (window.scrollMaxX)
	w += window.scrollMaxX;
	return w;
}
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
	obj['e'+type+fn] = fn;
	obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
	obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
	obj.addEventListener( type, fn, false );
}
function replaceSlashes( string ) {
	string = string.replace(/\//gi, '%2G');
	return escape(string);
}

function sbScrollPos(){
	var position = 0;
	if (navigator.appName == "Microsoft Internet Explorer"){
		position = (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
	} else{
		position = window.pageYOffset;
	}
	return position;
}
function sbHandleMargins(){
	var margin = document.body.style.margin;
	var padding = document.body.style.padding;
	
	if(isNaN(parseInt(sbDefaultMargin)) || parseInt(sbDefaultMargin)>0){
		document.body.style.margin = '0px';
	}
	
	if(isNaN(parseInt(sbDefaultPadding)) || parseInt(sbDefaultMargin)>0){
		document.body.style.padding = '0px';
	}
}
function detectBrowserVersion(){
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	}else 
		var ieversion = 0;
		return ieversion;
}
function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}
function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}
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 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;
}

addEvent(window, 'resize', function(event) {
	if(document.getElementById('wizard_curtain') != null){
		resize_curtain(sb_player_height);
	}
});

addEvent(window, 'scroll', function(event) {
	if(document.all){
		if(document.getElementById('wizard_curtain') != null){
			var ie_scroll_top = document.documentElement.scrollTop;
			document.getElementById('wizard_curtain').style.marginTop = ie_scroll_top + 'px';
		}		
	}
});