// JavaScript Document
var linkimg = "http://madli.net/wp-content/js/halalbadge_left.png";
var imgWidth = 260;
var imgHeight = 144;
var bannerWidth = (imgWidth / 2);

document.write('<div id="cornerBanner" style="position:absolute;z-index:10;width:' + (imgWidth/2) + 'px;overflow:hidden;" type="slidingDoors2" sdDir="backwards" sdWidth="' + (imgWidth/2) + '"><img src="'+linkimg+'" width="' + imgWidth +'" height="' + imgHeight +'" border="0"/></div>');
function initSD(container){
	
	
	var aTmp = new Array();
	
	aTmp[0] = container.getElementsByTagName('td');
	aTmp[1] = container.getElementsByTagName('div');
	
	for(i=0;i<aTmp.length;i++){
		for(j=0;j<aTmp[i].length;j++){
			var thisObj = aTmp[i][j];
			
			if(!thisObj.getAttribute('sdDir'))
				var direction = "forward";
			else
				var direction = thisObj.getAttribute('sdDir');
			
			if(thisObj.getAttribute('type') == "slidingDoors"){
				thisObj.style.width=thisObj.getAttribute('sdWidth') + "px";
				thisObj.style.background="url(" + thisObj.getAttribute('slidingImg') + ") no-repeat";
				if(direction == "backwards"){
					thisObj.style.backgroundPosition = thisObj.getAttribute('sdWidth') + 'px';
					thisObj.onmouseover = new Function("this.style.backgroundPosition = '0px';");
					thisObj.onmouseout = new Function("this.style.backgroundPosition = '-" + thisObj.getAttribute('sdWidth') + "px';");
				}else{
					thisObj.onmouseover = new Function("this.style.backgroundPosition = '-" + thisObj.getAttribute('sdWidth') + "px';");
					thisObj.onmouseout = new Function("this.style.backgroundPosition = '0px';");
				}
			}
			if(thisObj.getAttribute('type') == "slidingDoors2"){
				if(direction == "backwards"){
					thisObj.scrollLeft = thisObj.getAttribute('sdWidth');
					thisObj.onmouseover = new Function("this.scrollLeft = '0';");
					thisObj.onmouseout = new Function("this.scrollLeft = '" + thisObj.getAttribute('sdWidth') + "';");
				}else{						
					thisObj.onmouseover = new Function("this.scrollLeft = '" + thisObj.getAttribute('sdWidth') + "';");
					thisObj.onmouseout = new Function("this.scrollLeft = '0';");
				}
			}	
		}
	}		
	return;
}

function moveBanner() {
  
  var scrOfX = 0, scrOfY = 0;
  var marginfix = 0;
  
  //var bdWidth = $('resizeReference').offsetWidth;	// To get actual width of browser; as IE will use document content width if it overflows horizontally .... HATE IE !!!
  
  if (document.getElementById && !document.all){  // Detect Firefox (and NS6+) exclusively
	//Netscape, Firefox compliant
	scrOfY = window.pageYOffset;
	scrOfX = window.pageXOffset;
	
  } else if (document.getElementById){	// Detect IE5+ 
	//IE6 standards compliant mode
	scrOfY = document.documentElement.scrollTop;
	scrOfX = document.documentElement.scrollLeft;

	if(!document.body.currentStyle.marginRight){
		marginfix += 10;
	}
	if(!document.body.currentStyle.marginLeft){
		marginfix += 10;
	}
	// account for left margin space
	if(document.body.currentStyle.marginRight && parseInt(document.body.currentStyle.marginRight.substr(0,document.body.currentStyle.marginRight.indexOf('p'))) != 0)
		marginfix += parseInt(document.body.currentStyle.marginRight.substr(0,document.body.currentStyle.marginRight.indexOf('p')));

	// account for right margin space
	if(document.body.currentStyle.marginLeft && parseInt(document.body.currentStyle.marginLeft.substr(0,document.body.currentStyle.marginLeft.indexOf('p'))) != 0)
		marginfix += parseInt(document.body.currentStyle.marginLeft.substr(0,document.body.currentStyle.marginLeft.indexOf('p')));
	
	
	// account for right padding space
	if(document.body.currentStyle.paddingRight && parseInt(document.body.currentStyle.paddingRight.substr(0,document.body.currentStyle.paddingRight.indexOf('p'))) != 0)
		marginfix += parseInt(document.body.currentStyle.paddingRight.substr(0,document.body.currentStyle.paddingRight.indexOf('p')));
	
	// account for left padding space
	if(document.body.currentStyle.paddingLeft && parseInt(document.body.currentStyle.paddingLeft.substr(0,document.body.currentStyle.paddingLeft.indexOf('p'))) != 0)
		marginfix += parseInt(document.body.currentStyle.paddingLeft.substr(0,document.body.currentStyle.paddingLeft.indexOf('p')));
	
  } 
	
  $('cornerBanner').setStyle({
		top: scrOfY+ 'px',
		//left: '0px'
		//left: (scrOfX + bdWidth + marginfix - bannerWidth) + 'px' 
		left: (scrOfX + marginfix) + 'px' 
	});
}




// PNG Fix
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}


moveBanner();
initSD(document); 

// position banner after page load to handle any scrollbar padding
if(window.onload){
	var oldFunc = window.onload;
	window.onload = function () { oldFunc();moveBanner();}
}else{
	window.onload = function () { moveBanner(); }
}
if(window.onscroll){
	var oldFunc = window.onscroll;
	window.onscroll = function () { oldFunc();moveBanner(); }
}else{
	window.onscroll = function () { moveBanner(); }
}
if(window.onresize){
	var oldFunc = window.onresize;
	window.onresize = function () { oldFunc();moveBanner(); }
}else{
	window.onresize = function () { moveBanner(); }
}


