var _qacct="p-6avBXUSnw-AD6";
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-336964-4']);
_gaq.push(['_trackPageview']);
if (_is_logged_in) _gaq.push(['_setVar', 'LoggedIn']);
else _gaq.push(['_setVar', 'LoggedOut']);

var num_adsense_units = 0;

function addLoadHandler(f) {
    if (window.addEventListener) window.addEventListener('load', f, false);
    else if (window.attachEvent) window.attachEvent('onload', f);
}

var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];

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(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

if(window.location.pathname.search("blog")<0) {
    createCookie("thescript",_this_script,1);
} else {
    createCookie("thescript","blogpost",1);
}

var spacer_height2 = 0;


function run_LeftAds() {
	var headID = document.getElementsByTagName("head")[0];         
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = '/forums/clientscript/iptf_leftads.css';
	cssNode.media = 'screen';
	headID.appendChild(cssNode);
}


googletag.cmd.push(function () {
	if(_this_script != 'register') {
		googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_Toplink', [234, 21], 'div-IPTF-Toplink').addService(googletag.pubads());
        googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_Button_1', [160, 160], 'div-IPTF-Button-1').addService(googletag.pubads());

		if (!_is_logged_in) {
			if (_this_script == 'showthread') {
				googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_Signature', [300, 250], 'div-IPTF-ROS-Signature').addService(googletag.pubads());
                num_adsense_units++;
			}
			if (_this_script == 'vb_comment_bridge' && window.location.pathname.search("blog")>=0) {
				googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_Blogpost', [300, 250], 'div-IPTF-Blogpost').addService(googletag.pubads());
                num_adsense_units++;
			}
			if (_this_script == 'vb_comment_bridge') {
				googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_FP_First_Post', [300, 250], 'div-IPTF-FP-First-Post').addService(googletag.pubads());
                num_adsense_units++;
			}
            if (_this_script == 'vb_comment_bridge' && window.location.pathname.search("blog")<0) {
				googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_FP_Second_Post', [300, 250], 'div-IPTF-Second-Post').addService(googletag.pubads());
                num_adsense_units++;
			}
			if (_this_script == 'showthread' && _show_second_post_ad) {
				googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_Second_Post', [300, 250], 'div-IPTF-Second-Post').addService(googletag.pubads());
                num_adsense_units++;
			}
			/*
			if (_this_script == 'index') {
				googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_Forumhome_First', [300, 250], 'div-IPTF-Forumhome-First').addService(googletag.pubads());
                num_adsense_units++;
			}
			*/
			if(_this_script == 'index' || _this_script == 'showthread' || _this_script == 'forumdisplay' || _this_script == 'search'  || _this_script == 'member' || _this_script == 'tags') {
				googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_ATF_Rectangle', [300, 250], 'div-IPTF-ROS-ATF-Rectangle').addService(googletag.pubads());
				num_adsense_units++;
			}
		}
        
        var spacer_height = document.getElementById("the_spacer").offsetHeight;
        spacer_height2 = spacer_height;
        var show_second_skyscraper = (spacer_height > 990 || (!_is_logged_in && spacer_height > 690 ));
	
		if (_iptf_forumlist) {
			//googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_ATF_Rectangle', [300, 250], 'div-IPTF-ROS-ATF-Rectangle').addService(googletag.pubads());
			googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_Skyscraper1', [160, 600], 'div-IPTF-ROS-Skyscraper1').addService(googletag.pubads());
			num_adsense_units++;
			if(show_second_skyscraper) {
                var show_third_skyscraper = ((num_adsense_units < 3) && (spacer_height > 1590 || (!_is_logged_in && spacer_height > 1290 )));
				
				
				googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_Skyscraper2', [160, 600], 'div-IPTF-ROS-Skyscraper2').addService(googletag.pubads());
				num_adsense_units++;

                if(show_third_skyscraper) {
                    googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_Skyscraper3', [160, 600], 'div-IPTF-ROS-Skyscraper3').addService(googletag.pubads());
                    num_adsense_units++;
                }
			}
		}
        if(show_second_skyscraper) {
            googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_Header', [728, 90], 'div-IPTF-ROS-Header').addService(googletag.pubads());
        }
    }
    
    googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_Bot_Small_Rectangle', [300, 250], 'div-IPTF-ROS-Bot-Small-Rectangle').addService(googletag.pubads());
    googletag.defineUnit('/1002333/ca-pub-5036526775270475/IPTF_ROS_Bot_Rectangle', [600, 250], 'div-IPTF-ROS-Bot-Rectangle').addService(googletag.pubads());

    googletag.pubads().setTargeting('sitepage', _this_script);
    
    if(_is_logged_in) {
    	googletag.pubads().setTargeting('loggedin', "true");
    	createCookie("loggedin","true",1);
    }
	else {
		googletag.pubads().setTargeting('loggedin', "false");
		createCookie("loggedin","false",1);
	}

    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
});


function run_GA_tracking() {
    var ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ga, s);
}

function run_DFP() {
    var gads = document.createElement('script');
    gads.async = true;
    gads.type = 'text/javascript';
    gads.src = "http://www.googletagservices.com/tag/js/gpt.js";
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gads, s);
}

function run_Quant() {
	var vib = document.createElement('script');
	vib.async = true;
	vib.type = 'text/javascript';
	vib.src = "http://edge.quantserve.com/quant.js";
	var node = document.getElementsByTagName('script')[0];
	node.parentNode.insertBefore(vib, node);
}

function run_Vib() {
	var vib = document.createElement('script');
	vib.async = true;
	vib.type = 'text/javascript';
	if(_this_script == 'vb_comment_bridge')
		vib.src = "http://ipodtouchfans.us.intellitxt.com/intellitxt/front.asp?ipid=16341";
	else
		vib.src = "http://ipodtouchfans.us.intellitxt.com/intellitxt/front.asp?ipid=23068";
	document.body.appendChild(vib);
}


/*
if (!_is_logged_in && _this_script != 'register') {
    addLoadHandler(run_Vib);
}
*/
