/**
*
*   global.js
*
*   This JS file include will hold all global functionality.
*   Global is defined as appearing on more than one type of page.
*
*/
$(function() {

	initMantle();
	initMantleSidebar();
	//rotateAds(); // Stopped auto refresh 01/03/2012.
	
	var xp = 20;
	var yp = 70;
	var exp_cp = 60;
	var name_cp = 'sub_pop';
	var cp_val = readCookie(name_cp);
	var pop_timeout = 10000;
	
	if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }

	var width = myWidth;
	var left = (width / 2) - 275;

    if (!cp_val) {
        $("#sub_pop").css('display', 'block');
        $("#sub_pop").css('left', left);
        createCookie(name_cp,1,exp_cp); 
    }
    
    $('#pop_click,#pop_close').click(function() {
		$('#sub_pop').hide();
	});

	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	$("#expand-small").mouseover(function() {
		$("#expand-small").hide();
		$("#expand-big").show();
	});

	$("#expand-big").mouseout(function() {
		$("#expand-small").show();
		$("#expand-big").hide();
	});

});

/**
*
*    Mantle
*
*    Generates the Mantle Module Which Slides the Featured Content On Homepage
*    Added By: Tito To (5/27/2009)
*/
function rotate() {

	//Get the first image
	var currentImg = ($('.contentdiv.show') ?  $('.contentdiv.show') : $('.contentdiv:first'));
	var currentNo = ($('.toc.selected') ?  $('.toc.selected') : $('.toc:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var nextImg = ((currentImg.next().length && !currentImg.next().hasClass('pagination')) ? ((currentImg.next().hasClass('show')) ? $('.contentdiv:first') : currentImg.next()) : $('.contentdiv:first'));
	var nextNo = ((currentNo.next().length) ? ((currentNo.next().hasClass('selected')) ? $('.toc:first') : currentNo.next()) : $('.toc:first'));

	//Set the fade in effect for the next image, the show class has higher z-index
	nextImg.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 700);
	nextNo.addClass('selected');

	//Hide the current image
	currentImg.animate({opacity: 0.0}, 700)
	.removeClass('show');
	currentNo.removeClass('selected');

};

function initMantle() {

	//Get the first image and display it (gets set to full opacity)
	$('.contentdiv:first').css({opacity: 1.0})
	.addClass('show');

	$('.indicators').css({opacity: 1.0})
	$('.toc:first').addClass('selected');

	//var set = setInterval('rotate()',6000);	

	$('.toc').click(function(event) {
		//Clear out timer
		clearInterval(set);

    var url = this.toString();
    var delimiter = '#';
    var id = url.split(delimiter);
    id = parseInt(id[1]);

    $('.contentdiv.show').css({opacity: 0.0})
		.removeClass('show');

		$('.contentdiv.content_'+id).css({opacity: 1.0})
		.addClass('show');

    $('.toc.selected').removeClass('selected');

		$('.toc.content_'+id).addClass('selected');

		return false;
	});

}

function rotateSidebar() {	
 	
 	//Get the first image
 	var currentImg = ($('.contentdiv-sidebar.show') ?  $('.contentdiv-sidebar.show') : $('.contentdiv-sidebar:first'));
 	var currentNo = ($('.toc-sidebar.selected') ?  $('.toc-sidebar.selected') : $('.toc-sidebar:first'));

 	//Get next image, when it reaches the end, rotate it back to the first image
 	var nextImg = ((currentImg.next().length && !currentImg.next().hasClass('pagination')) ? ((currentImg.next().hasClass('show')) ? $('.contentdiv-sidebar:first') : currentImg.next()) : $('.contentdiv-sidebar:first'));
 	var nextNo = ((currentNo.next().length) ? ((currentNo.next().hasClass('selected')) ? $('.toc-sidebar:first') : currentNo.next()) : $('.toc-sidebar:first'));
 	
 	//Set the fade in effect for the next image, the show class has higher z-index
 	nextImg.css({opacity: 0.0})
 	.addClass('show')
 	.animate({opacity: 1.0}, 700);
 	nextNo.addClass('selected');

 	//Hide the current image
 	currentImg.animate({opacity: 0.0}, 700)
 	.removeClass('show');
 	currentNo.removeClass('selected');
 	
 };

function initMantleSidebar() {
 			
 	//Get the first image and display it (gets set to full opacity)
 	$('.contentdiv-sidebar:first').css({opacity: 1.0})
 	.addClass('show');
 	$('.toc-sidebar:first').addClass('selected');
 		
 	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
 	var set = setInterval('rotateSidebar()',10000);
 	
 	$('.toc-sidebar').click(function(event) {
 		//Clear out timer
 		clearInterval(set);
 		
         var url = this.toString();
         var delimiter = '#';
         var id = url.split(delimiter);
         id = parseInt(id[1]);
         
         $('.contentdiv-sidebar.show').css({opacity: 0.0})
 		.removeClass('show');

 		$('.contentdiv-sidebar.content_'+id).css({opacity: 1.0})
 		.addClass('show');
 		
         $('.toc-sidebar.selected').removeClass('selected');

 		$('.toc-sidebar.content_'+id).addClass('selected');
 		
 		return false;
 	});
 	
 }
 
function clearTimer() {
		
		clearInterval(set);
	}

/**
*
*   Toggles Tabs
*
*   This function will toggle through tabs or any other ID'd DOM elements, showing the selected
*   tab.  It also has the option to change the tab CSS styles.
*
*   @param array options Options List (Example: ['MyVideos','FavoriteVideos','TaggedVideos'])
*   @param string selected Selected Option (Example: 'TaggedVideos')
*   @param string offClass Tab 'Off Class' CSS Classes To Set
*   @param string onClass Tab 'On Class' CSS Classes To Set
*   @return void
*
*/
function toggle_tabs(options, selected, offClass, onClass) {
	if (options instanceof Array) {
    	for (var i=0; i<options.length; i++) {
            if (document.getElementById(options[i])) {
                document.getElementById(options[i]).style.display = 'none';
            }
            if (typeof(offClass) != 'undefined') {
                if (document.getElementById(options[i]+'Tab')) {
                    document.getElementById(options[i]+'Tab').className = offClass;
                }
            }
        }
	} else {
        if (document.getElementById(options)) {
            document.getElementById(options).style.display = 'none';
        }
        if (typeof(offClass) != 'undefined') {
            if (document.getElementById(options+'Tab')) {
                document.getElementById(options+'Tab').className = offClass;
            }
        }
	}
    if (selected instanceof Array) {
    	for (var i=0; i<selected.length; i++) {
	        if (document.getElementById(selected[i])) {
	            document.getElementById(selected[i]).style.display = 'inline';
	        }
	        if (typeof(onClass) != 'undefined') {
	            if (document.getElementById(selected[i]+'Tab')) {
	                document.getElementById(selected[i]+'Tab').className = onClass;
	            }
	        }
    	}
    } else {
        if (document.getElementById(selected)) {
            document.getElementById(selected).style.display = 'inline';
        }
        if (typeof(onClass) != 'undefined') {
            if (document.getElementById(selected+'Tab')) {
                document.getElementById(selected+'Tab').className = onClass;
            }
        }
    }
}

/**
*
*   Refreshes Ads Position Every 40 Seconds
*   @lib JQuery
*   @return void
*
*   @param object ad_timer Timeout Object
*
*/

// Stopped auto refresh 01/03/2012.
/*	

var setRotate;
function rotateAds() {

    var html1 = '<iframe src="http://ad.doubleclick.net/adi/canoekayak.primedia.com/'+ ads_params +';tile=7;sz=728x90;pos=top;ord=' + ord + '?" width="728" height="90" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>';
    var html2 = '<iframe src="http://ad.doubleclick.net/adi/canoekayak.primedia.com/'+ ads_params +';tile=9;pos=top;sz=300x250;ord=' + ord + '?" width="300" height="250" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>';
    var html3 = '<iframe src="http://ad.doubleclick.net/adi/canoekayak.primedia.com/'+ ads_params +';tile=11;pos=bottom;sz=300x250;ord=' + ord + '?" width="300" height="250" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>';
    var html4 = '<iframe src="http://ad.doubleclick.net/adi/canoekayak.primedia.com/'+ ads_params +';tile=13;sz=160x600;ord=' + ord + '?" width="160" height="600" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>';
    var html5 = '<iframe src="http://ad.doubleclick.net/adi/canoekayak.primedia.com/'+ ads_params +';tile=16;pos=bottom;sz=728x90;ord=' + ord + '?" width="728" height="90" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>';

    if ($('#ad-728-top').length > 0) { $('#ad-728-top').html(html1); }
    if ($('#ad-300-top').length > 0) { $('#ad-300-top').html(html2); }
    if ($('#ad-300-bottom').length > 0) { $('#ad-300-bottom').html(html3); }
    if ($('#ContainsSKY').length > 0) { $('#ContainsSKY').html(html4); }
    if ($('#ad-728-bottom').length > 0) { $('#ad-728-bottom').html(html5); }
    
		if (setRotate) {
			clearInterval(setRotate);
		}
		
 	initAds();

	
	}

function initAds() {
		if ($('.ads-rotate').length > 0) { 
			setRotate = setInterval('rotateAds()',40000);
		}	
	}
*/

/****************************************
 **
 **    Photo Gallery
 **
 ****************************************/

var Collection;
var showAnchor = true;
var firstImageID = '';
var CollectionComponent = function()
{
 this.images = {};

 // Loads Playlist
 this.Load = function(playlist) {

     // Loads Playlist
     try {
         this.images = $.parseJSON(playlist);
     } catch (e) {
    	 alert('Error parsing JSON');
         return false;
     }
     
     // Shows Initial Image
     if (typeof(GetID('#')) != 'undefined') {
         this.ShowImage(GetID('#'));
     } else if (typeof(GetID('?image=')) != 'undefined') {
         this.ShowImage(GetID('?image='));
     } else {
    	 showAnchor = false;
    	 firstImageID = this.images[0].id;
    	 this.ShowImage(this.images[0].id);	 
     }

     //Keylistener for Left/Right arrows
     $(document).bind('keydown', function(e) {
         if (e.which == '37') {
             Collection.ShowImage(Collection.prevID);
         }
         if (e.which == '39') {
             Collection.ShowImage(Collection.nextID);
         }
     });
     
 	var HashCheckInterval = setInterval(this.CheckForHash, 500);

 };

 // Show Image (Primary Function Call)
 this.ShowImage = function(id) {

     // Adds Anchor Tag With ID Of Current Image
	 if(showAnchor == true) {
		 document.location.href = "#"+id; 
	 } else {
		 showAnchor = true;
	 }

     this.ShowLoader();

     this.UpdatePhotoPaging(id); // <-- Updates Photo Paging, Per Image

 };

 // Shows Loader
 this.ShowLoader = function() {
     $('#imageLoaderGif').css('display','block');
 }

 // Hides Loader
 this.HideLoader = function() {
     $('#imageLoaderGif').css('display','none');
     $('#featured-photo').css('display','block');
 };

 // Updates Image
 this.UpdateFeatureImage = function(id,nextId) {
	 var image = this.GetImage(id);

	 $('#selectedImage').html('<a href="'+this.GetCollectionPath()+'#'+nextId+'" onclick="Collection.ShowImage(\''+nextId+'\');return false;"><img style="vertical-align:middle;" src="'+image.link+'" alt="" onload="Collection.HideLoader();return false;"/></a>');
	 
};

 // Updates Photo Paging
 this.UpdatePhotoPaging = function(id) {

     var currentPage = 0;
     var totalPages = 0;

     var currentNumber = 1;
     var totalImages = 0;
     var prevID = 0;
     var nextID = 0;
     var num = 0;

     if ($('#GalleryView').length > 0) {
         var noDisplayThumb = 8;
     }

     // Gets Total Image Count, Current Page
     var first = 0;
     var prev = 0;
     var count = 0;
     for (image in this.images) {
    	 if (image == 'filter' || image == 'indexOf') continue;
         count++;
         if ((count % noDisplayThumb) == 1) {
             totalPages++;
         }
         if (first == 0) {
             first = this.images[image].id;
         }
         if (this.images[image].id == id) { // <-- Image Match Found
             this.UpdateCaption(this.images[image].desc); // <-- Updates Caption, Per Image
             currentNumber = count;
             currentPage = totalPages;
             prevID = prev; // <-- Sets Previous Image ID (Or 0 If Image Is First Image)

         }
         if (prev == id) { // <-- Sets Next Image ID (Based On Cycle/Rotation)
             nextID = this.images[image].id;
         }
         prev = this.images[image].id;
         totalImages++;
     }

     if (totalImages > 0) {
         if (prevID == 0) { // <-- If PrevID Still Not Set, Use Last Image Found (As Image ID Was First Image)
             prevID = prev;
         }
         if (nextID == 0) { // <-- If NextID Still Not Set, Use First Image Found (As Image ID Was Last Image)
             nextID = first;
         }
     }

     this.prevID = prevID;
     this.nextID = nextID;

     this.UpdateFeatureImage(id,nextID); // <-- Updates Feature Image

     // Builds Pagination Arrows
     var html = '';
     html += '<a id="PrevImg" href="'+this.GetCollectionPath()+'#'+prevID+'" onclick="Collection.ShowImage(\''+prevID+'\');return false;">&lt; Previous</a>';
     html += currentNumber+' of '+totalImages+' ';
     html += '<a id="NextImg" href="'+this.GetCollectionPath()+'#'+nextID+'" onclick="Collection.ShowImage(\''+nextID+'\');return false;">Next &gt;</a>';
     $('#paginationLinks').html(html);
     
     //Building Image Pagination
     var html = '';
     html += '<a href="'+this.GetCollectionPath()+'#'+prevID+'" onclick="Collection.ShowImage(\''+prevID+'\');return false;"><img src="'+arrow_prev_active+'" /></a>';
     $('#previousPageImage').html(html);
     var html = '';
     html += '<a href="'+this.GetCollectionPath()+'#'+nextID+'" onclick="Collection.ShowImage(\''+nextID+'\');return false;"><img src="'+arrow_next_active+'" /></a>';
     $('#nextPageImage').html(html);

     // Builds Image Navigation
     var html = '';
     if (totalImages <= noDisplayThumb) {
         num = totalImages;
     } else {
         num = (totalImages % noDisplayThumb == 0) ? noDisplayThumb : (totalImages % noDisplayThumb);

     }

     if (currentPage == totalPages) {
         for (i=0; i<num; i++) {

             var startImg = ((currentPage-1) * noDisplayThumb) + i;
             var startImage = this.GetImage(this.images[startImg].id);

             html += '<img src="'+startImage.thumb+'" width="100" height="75" border="0" onclick="Collection.ShowImage(\''+this.images[startImg].id+'\');return false;" id="img_'+this.images[startImg].id+'"';
             if (this.images[startImg].id == id) {
                 html += ' class="selected"';
             } else {
                 html += ' class="notSelected"';
             }
             html += ' />';
         }

     } else { 
         for (i=0; i<noDisplayThumb; i++) {
 
             var startImg = ((currentPage-1) * noDisplayThumb) + i;
             var startImage = this.GetImage(this.images[startImg].id);

             html += '<img src="'+startImage.thumb+'" width="100" height="75" border="0" onclick="Collection.ShowImage(\''+this.images[startImg].id+'\');return false;" id="img_'+this.images[startImg].id+'"';
             if (this.images[startImg].id == id) {
                 html += ' class="selected"';
             } else {
                 html += ' class="notSelected"';
             }
             html += ' />';
         }
     }
     $('#photoThumbs').html(html);

     // Builds Previous Image Navigation Button
     /*var ppImage = document.getElementById('previousPageImage');
     if (currentPage == 1) {
         $('#previousPageImage').attr('src',arrow_prev_inactive);
         $('#previousPageImage').removeClass('cursoron');
         $('#previousPageImage').addClass('cursoroff');
         $('#previousPageImage').click(function() {});
     } else {
         var num1 = currentNumber - (currentNumber % noDisplayThumb + noDisplayThumb);
         imageID2 = this.images[num1].id; // <-- Define Before Sending Into 'onclick' Definition
         ppImage.src = arrow_prev_active;
         ppImage.className = 'cursoron';
         ppImage.title = '< Previous Page';
         ppImage.onclick = function() {
             Collection.ShowImage(imageID2);
         }
     }

     // Builds Next Image Navigation Button
     var npImage = document.getElementById('nextPageImage');
     if (totalPages > 1 && currentPage != totalPages) {
         var num2 = (currentPage * noDisplayThumb);
         imageID = this.images[num2].id; // <-- Define Before Sending Into 'onclick' Definition
         npImage.className = 'cursoron';
         npImage.src = arrow_next_active;
         npImage.title = 'Next Page >';
         npImage.onclick = function() {
             Collection.ShowImage(imageID);
         }
     } else {
         $('#nextPageImage').attr('src',arrow_next_inactive);
         $('#nextPageImage').removeClass('cursoron');
         $('#nextPageImage').addClass('cursoroff');
         $('#nextPageImage').click(function() {});
     }*/
          
 };

 // Updates Caption
 this.UpdateCaption = function(caption) {
     if (caption != '') {
    	 $('#photo-description').css('display','block')
         $('#imageDescription').html(caption);
     } else {
    	 $('#photo-description').css('display','none');
     }
 };
 
 // Updates share Facebook
 this.UpdateShareIcons = function(id) {/*
	 $('#shareFB').html('<fb:like href="'+this.GetCollectionSharePath()+id+'" show_faces="false" send="true"></fb:like>'); 
	 $('#shareTwitter').html('<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url='+encodeURIComponent(this.GetCollectionSharePath()+id)+'" style="width:130px; height:26px;"></iframe>'); 
	 try {
         FB.XFBML.parse();
     } catch (e) {}*/
 };
 // Gets Current Collection Path
 this.GetCollectionPath = function() {
     var url = window.location.href;
     var delimiter = '#';
     var segment = url.split(delimiter);
     return segment[0];

 };
 
 // Gets Current Collection Path for FB share
 this.GetCollectionSharePath = function() {
     var url = window.location.href;
     var segment = url.split('?image=');
     if (typeof(segment[1]) == 'undefined') {
    	 var segment = segment[0].split('#');
    	 return segment[0]+'?image=';
     } else {
    	 var image = segment[1].split('#');
    	 return segment[0]+'?image='; 
     }
 };

 // Gets Image Info
 this.GetImage = function(id) {
	 var imgObj;
	 var i;
     for(i in this.images) {
    	 if (this.images[i].id == id) {
			 imgObj = this.images[i]; 
		 }
	 }
     return imgObj;
 };

 /**
 *
 *   Check for image hash id and update featured photo accordingly
 *   @return void
 *
 */
 this.tempID;
 this.CheckForHash = function() {
	 var currentID = GetID('#');
	if(typeof(currentID) != 'undefined') {
		if (currentID != this.tempID) {
			this.tempID = currentID ;
			Collection.UpdateShareIcons(this.tempID);
			Collection.UpdatePhotoPaging(this.tempID);
		}
	} 
	else if(this.tempID != firstImageID) 
	{ 
		this.tempID = firstImageID;
		Collection.UpdateShareIcons(this.tempID);
		Collection.UpdatePhotoPaging(this.tempID); 
	}
};
 
} //end Collection

/**
*
*   Retrieves Anchor Tag From URL As ID
*   @return void
*
*/
function GetID(delimiter){
	var url = window.location.href;
	var id = url.split(delimiter);
	if (id[1] != '') {
	    return id[1];
	} else {
	    return '';
	}
}

/**
* GrindMedia Overlay Instantiation
* - NOTE: Only First "gmOverlay()" Call Will Initialize 
* @param string json JSON Overlay Definition
* @return void
*/
var overlay;
function gmOverlay(json) {
	if (!overlay) {
		var obj = jQuery.parseJSON(json);
		if (obj != null) {
			overlay = new OverlayComponent();
			$(document).ready(function() {
				overlay.video = obj.video;
				overlay.image = obj.image;
				overlay.link = obj.link;
				overlay.lifetime = obj.countdown;
				overlay.skiptime = obj.skip;
				overlay.init();
			});
		}
	}
}

/**
* GrindMedia Overlay Instantiation
* @param string json JSON Overlay Definition
* @return void
*/
function gmOverlayCallback() {
	if (overlay != null) {
		if (arguments[0] == 'REMAINING')
			overlay.updateCountdown(arguments[1]);
		else if (arguments[0] == 'COMPLETE')
			overlay.hideOverlay();
		else if (arguments[0] == 'CLICK-THRU') {
			window.open(arguments[1]);
			overlay.hideOverlay();
		}
	}
}

/**
* GrindMedia Photo Gallery Overlay Component
*/
var OverlayComponent = function() {

	this.image = '';
	this.video = '';
	this.link = '';
	this.duration = 0;
	this.lifetime = 0;
	this.skiptime = 0;

	this.init = function() {

		// Adjusts Overlay Height On Initialization
		this.adjustHeight();

		// Initializes Video Interstitial
		if (this.video) {
			var version = swfobject.getFlashPlayerVersion();
			if (version.major >= 10) {
				swfobject.embedSWF(
					'/wp-content/themes/surfermag.com/swf/interstitial.swf',
					'InterstitialOverlay',
					'950',
					'700',
					'10.0.0',
					'/wp-content/themes/surfermag.com/swf/swfobject-installer.swf',
					{video: this.video, link: this.link},
					{wmode: 'window'}
				);
				this.updateCountdown(0);
				$('#Interstitial').fadeIn();
				return;
			}
		}

		// Initializes Image Interstitial
		if (this.image) {
			var html = '<a href="' + this.link + '" onclick="window.open(this.href);return false;">';
				html += '<img src="' + this.image + '" />';
				html += '</a>';
			$('#InterstitialOverlay').html(html);
			$('#Interstitial').fadeIn();
			this.tick();
			return;
		}

	};

	// Artificial Image Countdown Ticker
	this.tick = function() {
		$(this).oneTime(1000, function(i) {
			this.updateCountdown(this.lifetime);
			if (--this.lifetime >= 0)
				this.tick();
			else
				this.hideOverlay();
		});
	};

	// Updates Advertisement Countdown
	this.updateCountdown = function(secs) {

		// Re-adjusts Overlay Height
		this.adjustHeight();

		// Updates Lifetime, Initializing Duration Where Applicable
		this.lifetime = secs;
		if (this.duration < this.lifetime)
			this.duration = this.lifetime;

		// Displays Close Button When Applicable
		if (this.lifetime == (this.duration - this.skiptime))
			this.showClose();

		// Displays Advertisement Countdown
		var html = 'This advertisement will close in ' + secs + ' seconds..';
		if (secs == 0)
			html = 'This advertisement will close in a moment..';
		$('#Interstitial .countdown').html(html);

	};
	
	this.adjustHeight = function() {
		if ($('#Interstitial .takeover').length > 0) {
			var height = $(document).height();
			var offset = $('#Interstitial .takeover').offset();
			$('#Interstitial .takeover').css('height', (height - offset.top));
		}
	};

	this.showClose = function() {
		$('#Interstitial .takeover').live('click', this.hideOverlay);
		$('#Interstitial .close').fadeIn();
	};

	this.hideOverlay = function() {
		this.lifetime = 0;
		$('#Interstitial .takeover').fadeOut(function() {
			$('#Interstitial .takeover').remove();
		});
	};

}


/**
*
*   Google Sponsored Ads
*
*   This function will is for Google Sponsored Links ads
*
*   @param none
*   @return void
*
*/
function google_ad_request_done(google_ads)
{var s='';var i;
var s = '<div class ="googleAdTitle"><a target="_new" class="ad_attribution" href="' + google_info.feedback_url + '">Sponsored Links</a></div>';
var multicolumns=false;if(google_ads.length==0)
return;if(google_ads[0].type=="text")
{if(column_count_afc>1)
{multicolumns=true;}
if(multicolumns==true)
s+='<table width="100%" class="google_afc_tbl" border="0" cellspacing="0" cellpadding="5">';for(i=0;i<google_ads.length;++i)
{if(multicolumns==true)
{if(i%column_count_afc==0)
s+='<tr>';s+='<td valign="top" width="25%">';}
var description=google_ads[i].line2+' '+google_ads[i].line3;var url_text=google_ads[i].visible_url;if(max_length_description>0)
description=description.substring(0,max_length_description);if(max_length_url>0)
url_text=url_text.substring(0,max_length_url);s+='<div '+css_class_item_cell+'><a target="_blank" href="'+google_ads[i].url+'" '+'onmouseout="window.status=\'\'" '+'onmouseover="window.status=\'go to '+
google_ads[i].visible_url+'\';return true;" '+
css_class_ads_title+'>'+
google_ads[i].line1+'</a><br /><span '+
css_class_ads_description+'>'+
description+'</span><br><a target="_blank" href="'+google_ads[i].url+'" '+'onmouseout="window.status=\'\'" '+'onmouseover="window.status=\'go to '+
google_ads[i].visible_url+'\';return true;" '+
css_class_ads_url+'>'+
url_text+'</a></div><br />';if(multicolumns==true)
{s+='</td>';if(i%column_count_afc==column_count_afc-1)
s+='</tr>';}}
if(multicolumns==true)
{s+='</table>';}}
document.write(s);return;}
function rewrite_google_header()
{var headers=document.getElementsByTagName('div');if((headers!=null)&&(headers.length>0))
{for(var i=headers.length-1;i>=0;i--)
{var att=headers[i].getAttribute("name");if(att=='adsByGoogleHeader')
{var color=get_element_style(headers[i],"color","color");if(typeof google_info!="undefined")
{headers[i].innerHTML='<a style\=\"color:'+color+'; text-decoration: none" target="_blank" class="ad_attribution" href="'+
google_info.feedback_url+'">'+headers[i].innerHTML+'</a>';}}}}}
function get_element_style(elem,ieStyleProp,cssStyleProp){if(elem.currentStyle){return elem.currentStyle[ieStyleProp];}else if(window.getComputedStyle){var compStyle=window.getComputedStyle(elem,"");return compStyle.getPropertyValue(cssStyleProp);}
return"";}	

