var gRoot = '/';
        jQuery(document).ready(
           function() {
/* banner ad */           
	var banWidth=600;
	var banHeight=1044;
       if(jQuery.browser.msie)
       {
         jQuery('#bannerimg').attr("src","images/swing-fore-yellow-800-70.jpg");
         jQuery('#bannerimg').attr("width","460");
         jQuery('#bannerimg').attr("height","800");
	 banWidth=460;
	 banHeight=800;

       }
   jQuery.fn.alignCenter = function() {
	var marginLeft =  - banWidth/2 + 'px';
	var marginTop =  - banHeight/2 + 'px';
	return jQuery(this).css({'margin-left':marginLeft, 'margin-top':marginTop});
   };

   jQuery.fn.togglePopup = function(){
     //detect whether popup is visible or not

     if(jQuery('#popup').hasClass('hidden'))
     {
	jQuery('#opaco').height(jQuery(document).height());
	jQuery('#opaco').toggleClass('hidden');
	jQuery('#opaco').animate({
	   "opacity": 0.7
	}, 500 );
	jQuery('#opaco').click(function(){jQuery(this).togglePopup();});

       jQuery('#popup').html(jQuery(this).html());
         jQuery('#popup').alignCenter();
         jQuery('#popup').toggleClass('hidden');
     }
     else
     {
       //visible - then hide
       jQuery('#opaco').toggleClass('hidden').unbind('click');
       jQuery('#popup').toggleClass('hidden');
     }
   };


	jQuery(window).resize(function() 
	{
       		if(jQuery.browser.msie)
		{
	    		return;
		}
	jQuery("#banner1 img").each(function() 
	{
        var maxWidth = jQuery(window).width(); // Max width for the image
        var maxHeight = jQuery(window).height()-40;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = 600; //jQuery('#banner1').width();    // Current image width
        var height = 1044; //jQuery('#banner1').height();  // Current image height


        // Check if current height is larger than max
        	if(height > maxHeight)
        	{
        	    ratio = maxHeight / height; // get ratio for scaling image
        	    //alert('ratio='+ratio);
        	    jQuery(this).css("height", maxHeight);   // Set new height
        	    jQuery(this).css("width", width * ratio);    // Scale width based on ratio
        	    jQuery("#banner1").css("height", maxHeight);   // Set new height
        	    jQuery("#banner1").css("width", width * ratio);    // Scale width based on ratio
        	    width = width * ratio;    // Reset width to match scaled image
        	    banWidth = width * ratio;    // Reset width to match scaled image
			banHeight=maxHeight;
        	}
    	});

    });
    jQuery(window).resize();

           
               //Local anchors animation
               jQuery.localScroll();
               //Popup video player background
               var tVideoOverlayEl = jQuery("<div class='js-video-popup'></div>");
               jQuery('body').append(tVideoOverlayEl);
               tVideoOverlayEl.prepend("<div class='js-popup-head'><div class='close'>close</div><span class='js-popup-title'></span></div><div class='js-popup-content'></div>");
               var player = flowplayer(jQuery('.js-popup-content', tVideoOverlayEl).get(0), { src: gRoot + "swf/flowplayer-3.2.1.swf", wmode: 'opaque' });
               var tVideoOverlay = tVideoOverlayEl.overlay({
                   speed: 1000,
                   target: tVideoOverlayEl.get(0),
                   expose: '#CCC',
                   onClose: function() {
                       player.unload();
                   },
                   api: true
               });
               jQuery('.js-video-trigger').click(function() {
                   tVideoOverlay.load();
                   player.play(this.href);
                   jQuery('.js-popup-title', tVideoOverlayEl).html(this.title);
                   return false;
               });
               /*-- --- --*/
               var tWindowOverlayEl = jQuery("<div class='js-popup'></div>");
               jQuery('body').append(tWindowOverlayEl);
               tWindowOverlayEl.prepend("<div class='js-popup-head'><div class='close'>close</div><span class='js-popup-title'></span></div><div class='js-popup-content'></div>");
               var tWindowOverlay = tWindowOverlayEl.overlay({
                   speed: 3000,
                   target: tWindowOverlayEl.get(0),
                   expose: '#333',
                   onClose: function() {
                   },
                   api: true
               });
               jQuery('.js-text-window-trigger').click(function() {
                   tWindowOverlay.load();
                   jQuery('.js-popup-title', tWindowOverlayEl).html(this.title);
                   jQuery('.js-popup-content', tWindowOverlayEl).html(jQuery('.js-trigger-content', this).html());
                   return false;
               });
               /*-- --- --*/
               var tHostName = window.location.hostname;
               if(tHostName.indexOf('www.') === 0)
                  tHostName = tHostName.substring(4);
               jQuery('a[href^=http]').each(
                  function(){
                     if(this.href.indexOf(tHostName) > 0)
                        return;
                     jQuery(this).attr('target','_blank');
                  }
               );
               var tRotatedImages = jQuery('.rotator img');
               var tCurrentImageNum = -1;
               var tChangeImage = function(){
                   var tCurrentImage = tRotatedImages.eq(tCurrentImageNum);
                   tCurrentImageNum = ++tCurrentImageNum%tRotatedImages.length;
                   var tNextImage = tRotatedImages.eq(tCurrentImageNum);
                   tCurrentImage.fadeOut(3000);
                   tNextImage.fadeIn(3000);
               };
               setInterval(tChangeImage, 6000)
           }
        );

function startSponsorsRotator(){
   var tContainerDiv = jQuery("#chained").eq(0);
   var tItemsDiv = jQuery(".items:first", tContainerDiv).eq(0);
   var tReadyToStart = true;
   var tWidth = 0, tPosition = 0, tPositionEnd = tContainerDiv.width();
   tItemsDiv.children().each(function(){ var tW = jQuery(this).outerWidth();if(tW == 0) tReadyToStart = false; tWidth += jQuery(this).outerWidth(); });
   if(tReadyToStart) {
      tItemsDiv.width(tWidth);
      var tItemsDivClone = tItemsDiv.clone();
      tContainerDiv.append(tItemsDivClone);
      tItemsDivClone.css('top', (-tItemsDiv.outerHeight())).css('left', tWidth+1);
      setInterval(function(){
         tPosition -= 3;
         tItemsDiv.css('left', tPosition);
         tItemsDivClone.css('left', tWidth + tPosition);
         if(tWidth + tPosition <= 0)
            {
               tPosition = 0;
               var tTmp = tItemsDiv;
               tItemsDiv = tItemsDivClone;
               tItemsDivClone = tTmp;
            }
      }, 40);
   } else {
      setTimeout(startSponsorsRotator, 100);
   }
}


