var u_agent = navigator.userAgent;
var lc_obj = document.getElementById('leftcorner');

var it = document.getElementById('inlinetable');
var it2 = document.getElementById('inlinetable2');
var light_bulb = document.getElementById('light');

var is = document.getElementById('ixstart');
var vs= document.getElementById('video_span');
var video= document.getElementById('video');

function getWindowWidth() {
  var windowWidth = 0;
  if (typeof(window.innerWidth) == 'number') {
    windowWidth = window.innerWidth;
  }
  else {
    if (document.documentElement && document.documentElement.clientWidth) {
      windowWidth = document.documentElement.clientWidth;
    }
    else {
      if (document.body && document.body.clientWidth) {
	windowWidth = document.body.clientWidth;
      }
    }
  }
  return windowWidth;
}

function open_drawer (imageurl) {
  open_close = 1;
	if (Drawer.all['my-drawer']) {
		var dr = Drawer.all['my-drawer'];
		var absCoords = getAbsPosition(lc_obj);
		var mt_top = absCoords.y;
		var mt_left = absCoords.x;
		if (!dr.open) {
			//setContainer();
			//alert(document.getElementById('dummyx').style.backgroundImage);
		  //document.getElementById('dummyx').style.backgroundImage="url(" + imageurl + ")";
		  //document.getElementById("dummyx").style.display = "";
		  document.getElementById("theWorldPrivate").style.display = "none";
		  
			if (u_agent.indexOf('Opera') != -1){
				
			}
			else
			{
				dr.speed = .25;
			}
			it2.style.display="";
			light_bulb.style.display="none";
			dr.outer.style.top =  mt_top + 268 + 'px';
			dr.outer.style.left = mt_left  + 'px';	
			is.style.display = "none";
			document.getElementById('vl').style.left=mt_left + 135 + 'px';	
			document.getElementById('vl').style.top=mt_top + 225 + 'px';	
			document.getElementById('vl').style.display = "";	
			it.style.visibility="hidden";
			dr.activate();
			document.blah.query.select();
			document.blah.query.focus();
		}
		
	}
}
function drawer_close (imageurl) {
  open_close = 2;
	if (Drawer.all['my-drawer']) {
		var dr = Drawer.all['my-drawer'];
		if(it2.style.display=="none") {
			return;
		}		
		if (dr.open) {
			//setContainer();
			//document.getElementById('dummyx').style.backgroundImage="url(" + imageurl + ")";
		  //document.getElementById("dummyx").style.display = "none";
		  document.getElementById("theWorldPrivate").style.display = "";
		  
			var absCoords = getAbsPosition(lc_obj);
			var mt_top = absCoords.y;
			var mt_left = absCoords.x;
			if (u_agent.indexOf('Opera') != -1){
				
			}
			else
			{
				dr.speed = .07;
			}
			dr.activate();
			it2.style.display="none";
			light_bulb.style.display="";
			is.style.display = "";
			document.getElementById('vl').style.display = "none";			
			dr.outer.style.left =  mt_left + 'px';
			dr.outer.style.top =  mt_top + 272 + 'px';

			it.style.visibility="visible";
			document.blah.query.select();
			document.blah.query.focus();
		}		
	}
}

var u_agent = navigator.userAgent;
function init(imageurl) {
	//alert(window.clientLeft);
	var myDrawer = new Drawer('my-drawer', 0.25, Drawer.BOTTOM, false, adjustXonStart, adjustXonMove, null);
	if (document.blah.cat.value == 'video') {
		open_drawer(imageurl);
	}
    //addEvent(vs, 'click', toggleDrawer);
	//addEvent(video, 'click', toggleDrawer);
}
	
	function adjustXonMove() {
			setContainer();
			var drawer = Drawer.all['my-drawer'];
			//if (drawer.open)	alert(1);
	}
	function	adjustXonEnd() {
			//alert('onend');
			//setContainer();
	}
	
	function adjustXonStart() {
		var drawer = Drawer.all['my-drawer'];
		if (!drawer.open) {
				setContainer();
				
		} 

		//
	}
	

function getAbsPosition(e) {
  	      		var left = 0;
  	      		var top  = 0;
  	      		while (e.offsetParent) {
				left += e.offsetLeft;
  	      			top  += e.offsetTop;
	  	      	//alert(e.tagName + ' - ' + e.id + ' - ' + e.currentStyle.hasLayout + ' - ' + left + ' - ' + top);	
  	      			e    = e.offsetParent;
  	      		}
  	      		
  	      		left += e.offsetLeft;
  	      		top  += e.offsetTop;
  	      		
  	      		return {x:left, y:top};
  	      	}

function setContainer() {
	
	/*for non-javascript version*/
	var u_agent = navigator.userAgent;
	/*document.getElementById('latestBgIxquick').style.width="600px";
    document.getElementById('topdummytable').style.display = 'none';
    	
	document.getElementById('latestBgIxquick').style.background = "none";
	document.getElementById('bgLineIxquick').style.background = "none";
	
	
    if (u_agent.indexOf('Safari') != -1) {
		document.getElementById('bgLineIxquick').style.background = "none";
		
	}
	
	document.getElementById('leftcornercontrol').style.paddingLeft="109px";
	document.getElementById('leftcornercontrol').style.paddingTop="28px";*/
	
  if (document.getElementById) {
    //alert(1);
    var windowWidth = getWindowWidth();
    var lc_obj = document.getElementById('leftcorner');
    var absCoords = getAbsPosition(lc_obj);
    var mt_top = absCoords.y;
    var mt_left = absCoords.x;

    /** Adding for 'firefox' re-sizing issue */
    if ((u_agent.indexOf('Firefox') != -1) || (u_agent.indexOf('Safari') != -1)) {
      if(mt_left<=1){
        mt_left = 25;
      }
    }

	if (document.getElementById('pa_cont')) {
       // Long powersearch text placement on homepage

        if (document.getElementById('poweralign')) {
		  document.getElementById('pa_cont').innerHTML = '';
		  document.getElementById('poweralign').style.display = '';
		  document.getElementById('poweralign').style.top = mt_top + 159 + 'px';
		  document.getElementById('poweralign').style.left = mt_left + 406 + 'px';
        }
    }
    var drawer = Drawer.all['my-drawer'];
    if (drawer) {//&& !drawer.moving) {
      if (!drawer.open) {	
	drawer.outer.style.left = mt_left  +'px';
	drawer.outer.style.top =  mt_top + 262 + 'px';
      }
      else
	{
	  drawer.outer.style.left = mt_left + 'px';
	  drawer.outer.style.top =  mt_top + 268 + 'px';
	  //alert(mt_left);
	}
    }
    //document.getElementById('dummyx').style.left=mt_left+'px';
    //document.getElementById('dummyx').style.top=mt_top+250+'px';
	//document.getElementById('dummyx').style.display="";/*for non-javascript version*/
    //document.getElementById('centercontent').style.left=mt_left+'px';
	//alert(document.getElementById('centercontent').style.left);
	
    /*document.getElementById('centercontent').style.top=mt_top+'px';
    document.getElementById('centercontent').style.display="";
    document.getElementById('inlinetablecont').style.left=mt_left+28+'px';
    document.getElementById('inlinetablecont').style.top=mt_top+308+'px';
	document.getElementById('inlinetablecont').style.display="";
    document.getElementById('back').style.left=mt_left-198+'px';
    document.getElementById('back').style.top=mt_top-60+'px';
	document.getElementById('back').style.display="";
    document.getElementById('back_repeat').style.left=0+'px';
    document.getElementById('back_repeat').style.top=mt_top-52+'px';
    if (u_agent.indexOf('MSIE') != -1) {
      document.getElementById('back_repeat').style.width=windowWidth +'px';
    } else if (u_agent.indexOf('Safari') != -1) {
      document.getElementById('back_repeat').style.width=windowWidth;
	} else if ((u_agent.indexOf('Mac') != -1) && (u_agent.indexOf('Opera') != -1)) {
	  document.getElementById('back_repeat').style.width=windowWidth-15+'px';
	}
    else{
	  //document.getElementById('back_repeat').style.width=windowWidth-16+'px';
	  document.getElementById('back_repeat').style.width=windowWidth+'px';
    }

	document.getElementById('back_repeat').style.display="";*/
    //document.getElementById('cont').style.backgroundImage="url(/s/daybreak/graphics/table_bg.gif)";
    document.getElementById('cont').style.visibility="visible";
    if (document.getElementById('vl')) {
            document.getElementById('vl').style.left=mt_left + 135 + 'px';
            document.getElementById('vl').style.top=mt_top + 225 + 'px';
    }
   	document.blah.query.select();
    document.blah.query.focus();

  }
}

function onLoadPage (imageurl) {
  //document.getElementById('dummyx').style.backgroundImage="url(" + imageurl + ")";
	setContainer();
	init(imageurl);
	//document.getElementById('lc2').style.display = "none";
}
//addEvent(document, 'resize', close_drawer);
window.onresize = function(e) {
	

		setContainer();
		if(document.getElementById('bookmark')) {
			pos_picker_re('open', 30, -215, 'bookmark');
		}
	
	
	//drawer.activate();
	/*if (drawer.open != false && !drawer.moving) {
		
		uncheckall('web','phone','video','pics'); 
		changeImages('web', 'http://us.ixquick.com/graphics/radio_C.gif'); 
		close_drawer ();
	}*/
}
