//** jQuery Scroll to Top Control script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** Available/ usage terms at http://www.dynamicdrive.com (March 30th, 09')
//** v1.1 (April 7th, 09'):
//** 1) Adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
//** 2) Fixes scroll animation not working in Opera. 
var padd =35;
var wid = 55;
var banner_leftpad = 85;
var banner_pad_btm = 0;
var wndheight = screen.height;
var browser =  navigator.appName =='Microsoft Internet Explorer' ? 1 : 0;

function alertSize() {
      myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
      }
      return myHeight;
    }
    
   var lptpheight = alertSize();

//alert("sdsd");
//var leftpixels =0 ;
//	if(document.body.clientWidth > 1000)
//	  leftpixels = (document.body.clientWidth - (1000-24))/2 ;
////	if(document.body.clientWidth==768)
////	  leftpixels = 18;	
//  if(document.body.clientWidth < 1000)
//	  leftpixels = 18;	
//	alert(leftpixel);  
//alert(screen.width);
//alert(screen.width);
 if(screen.width==1024)
 {
 padd= 35;
 if(browser==1)
    banner_pad_btm = 20;
 else if(lptpheight==640)
      banner_pad_btm = 70;
 else
    banner_pad_btm = 0;
 }
// padd= '35px;';
  if(screen.width==1152)
 {
 padd= 95;
 wid = wid + 60;
 if(browser==1) // IE
    banner_pad_btm = 115;
  else // FF
    banner_pad_btm = 95; 
 }
 if(screen.width==1280)
 {
 padd= 150;
  wid = wid + 115;
   if(browser==1) // IE
   {
        if(wndheight==768)
          banner_pad_btm = 20;//parseInt((wndheight * 20)/100);
        else if(wndheight==800)
         banner_pad_btm = 57;
        else if(wndheight==960)
          banner_pad_btm = 209;
        else
          banner_pad_btm = 275;
   }
  else
   {
      if(wndheight==768)
          banner_pad_btm = 0;//parseInt((wndheight * 20)/100);
       else if(wndheight==800)
         banner_pad_btm = 70;
        else if(wndheight==960)
          banner_pad_btm = 194;
        else
          banner_pad_btm = 260;
   }
 //banner_leftpad = banner_leftpad + 256; 
 }
//   if(screen.width==1280)
// {
// padd= '150px;';
// }

//	if(document.body.clientWidth > 1000)
//	{
//	  padd = (document.body.clientWidth - (1000-24))/2 ;
//   )
//  if(document.body.clientWidth < 1000)
//    { 
//    padd = 35;
//    }	
//var ScrollTop7 = document.body.scrollTop;
//if (ScrollTop7 == 0)
//{
//    if (window.pageYOffset)
//        ScrollTop7 = window.pageYOffset;
//    else
//        ScrollTop7 = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
//}

//alert(ScrollTop7);




 var x = 0;   
 var k = 0;
 var padbottom;
   if(self.innerHeight)
    {  
     x = self.innerWidth; 
    } 
    else if(document.documentElement && document.documentElement.clientHeight)
    {
     x = document.documentElement.clientWidth; 
    }
    else if(document.body)
    {
     x = document.body.clientWidth; 
    }
   
    //alert(x);
   if(x > 1000)
   {
	//alert(x);
    k = (x - (1000))/2 ;
    //alert(k);
    padd= (k -100) ;
	
    }
    if(x < 1000)
    { 
    padd = 30;
    }
    
    var paddbottom;
    paddbottom = '1px';
   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
   if (ieversion>=8)
    paddbottom = '2px';
   else if (ieversion>=7)
     paddbottom = '1px';
   } 
   
//alert(k);
var leftpad = (padd + 880) ; 
var html_content =  '<div style="z-index:1; left:'+leftpad+'px ; position:fixed width:251px;"  > \
                    <table border="0" cellspacing="0" cellpadding="0" align="left"> \
                      <tr> \
                      <td align="left"   style=" padding-bottom :'+paddbottom+'; padding-right :20px;" > \
                     <a style="outline-width:0px;" href="http://www.birdpark.com.sg/"  target="_blank" ><img src="images/jurong_attraction.png"  id="IMG2"  border="0" height="96px" style ="vertical-align :bottom ;"></a></td> \
                       <td align="left"  style="padding-bottom :'+paddbottom+'; padding-left:2px;" >  <a style="outline-width:0px;" href="http://www.zoo.com.sg/" target="_blank"><img src="images/singapore_zoo.png"  border="0"  height="98px" style ="vertical-align :bottom; text-align :left; "/></a></td> \
                         </tr> \
            </table> </div>'; 
            
        
            
          /*    <a href=”linktoexternalurk” target=”_blank”><img src=”images/banners/banners/” style=”border: 0px;”></a> \
          
          var html_content =  '<div style="z-index:-1; left:5px;" ><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"> \
                <tr> \   
                    <td align="left" valign="bottom" style="padding-left:'+padd+'" > \ width="103" height="140" /width="120" height="140"
                        <img src="images/links.png" width="223" border="0" height="140"  id="IMG2"  onclick="window.location.href("'test.aspx'");" /> </a></td> \
                </tr> \
            </table> </div>'; */
                
                
//alert(html_content);
var scrolltotop_2={
	//startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
	//scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
	setting: {startline:1, scrollto: -1, scrollduration:1000, fadeduration:[500, 100]},
	controlHTML: html_content, //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
	controlattrs: {offsetx:0, offsety:39}, //offset of control relative to right/ bottom of window corner
	anchorkeyword: '', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links

	state: {isvisible:false, shouldvisible:true},

	scrollup:function(){
		if (!this.cssfixedsupport) //if control is positioned using JavaScript
			this.$control.css({opacity:0}) //hide control immediately after clicking it
		var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
		if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
			dest=jQuery('#'+dest).offset().top
		else
			dest=-1
		//this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
	},

	keepfixed:function(){
		var $window=jQuery(window)
		var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
		var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
		this.$control.css({left:controlx+'px', top:controly+'px'})
	},

	togglecontrol:function(){
		var scrolltop=jQuery(window).scrollTop()
		if (!this.cssfixedsupport)
			this.keepfixed()
		this.state.shouldvisible=true; //(scrolltop>=this.setting.startline)? true : false
		if (this.state.shouldvisible && !this.state.isvisible){
			this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
			this.state.isvisible=true
		}
		else if (this.state.shouldvisible==false && this.state.isvisible){
			this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
			this.state.isvisible=false
		}
	},
	
	init:function(){
		jQuery(document).ready(function($){
			var mainobj=scrolltotop_2
			var iebrws=document.all
			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
			mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
			mainobj.$control=$(mainobj.controlHTML)
			//mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'arrow'})
				//.attr({title:'Scroll Back to Top'})
				//.click(function(){mainobj.scrollup(); return false})
				.appendTo('body')
			if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
				mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
			mainobj.togglecontrol()
			//$('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
			//	mainobj.scrollup()
			//	return false
			//})
			$(window).bind('scroll resize', function(e){
				mainobj.togglecontrol()
			})
		})
	}
}

scrolltotop_2.init()