/*  js for ad serving 

need to hide these layers...

imageContainer
image_info
*/




Page.photos = {
	
	freq : 5,
	duration : 8000,
	params : [],
	displayAd : false,
	adTimer : {},
	hide : function() {
		Page.hide('photoGalleryTitle','content_title','content_a','content_b');
	},
	
	show : function() {
		Page.show('photoGalleryTitle','content_title','content_a','content_b');
	},
	
	getParams : function() {
		// retrieve the query params from the location
		try{
			var searchString = location.search.substring(1);
			//alert(searchString);
			var temparray = searchString.split('&');
			
			for(var i = 0; i < temparray.length; i++){
				var temparray2 = temparray[i].split('=');
				this.params[temparray2[0]] = temparray2[1];
			}
		}catch(e){}
	},
	
	displayAdFunc : function() {
	
		System.out.println('displayAd');
		document.write('<style type="text/css">');
		//document.write('#photoGalleryTitle{visibility:hidden;}');
		//document.write('#content_title{visibility:hidden;}');
		document.write('#content_a{visibility:hidden;}');
		document.write('#content_b{visibility:hidden;}');
		//document.write('#shareContainer{visibility:hidden;}');
		
		//document.write('#relatedInfo{visibility:hidden;}');
		document.write('</style>');
	
		//Page.photos.hide();
		
		Page.photos.displayAd = true;
		
	
	},
	
	drawLink : function() {
	
		if(Page.photos.displayAd==true){
			System.out.println('drawLink');
			//clearTimeout(Page.photos.adTimer);
			//setTimeout('Page.photos.closeAd();',5000);		
			return document.write('<nobr><a href="javascript:Page.photos.closeAd();" style="color:#999999;">Skip This Ad &raquo;</a></nobr>');	
		}
	
	
	},
	
	closeAd : function() {
		System.out.println('closeAd');
		Page.hide('ad_content_layer');
		document.getElementById('ad_content_layer').innerHTML = '';
		this.show();
	
	},
	
	loadSeriesModule : function() {

		if((typeof(MTVN.Series.seriesId) != "undefined" && MTVN.Series.seriesId == "501") && Page.photos.params['fid'] != null) {

			$j("<div/>").attr("id", "related-series").insertBefore("#iphone_sponsor");
			var params = {};
			params.seriesId = MTVN.Series.seriesId;
			params.cid = Page.photos.params['fid'];

			$j.get("/global/music/videos/ajax/series_links.jhtml", params, function(data){
						$j("#related-series").empty().append(data);
				});

			}
	},
	
	testParams : function() {
		for(x in this.params){
			alert(x+' = '+this.params[x]);
		
		}
	},
	// we are in the image page
	// the page has completly loaded
	init : function() {
		// check the cookie
		// what is the fid???
		//alert(this.fid);
		Page.photos.getParams();
		
		//check the flipbook cookie 
		// if there is no cookie then set the cookie to this flipbookid plus the count which would be one.
		// cookie name = vh1photos
		// cookie value = 1563897-1
		var cookieValue = System.cookie.get('vh1photos');
		System.out.println('cookieValue='+cookieValue);
	
		if(cookieValue == undefined){
			System.out.println('setting cookie value now');
			System.cookie.set('vh1photos',Page.photos.params['fid']+'-0');
		}
		else{
			// the cookie is set
			var tempArray = cookieValue.split('-');
			var cookieFid = tempArray[0];
			var count     = tempArray[1];
			
			if(cookieFid==Page.photos.params['fid']){
				System.out.println('still in same flipbook');
				count++;
				if(count == Page.photos.freq){
					Page.photos.displayAdFunc();
					System.cookie.set('vh1photos',Page.photos.params['fid']+'-0');
				
				}
				else{
					System.out.println('increment cookie count');
					System.cookie.set('vh1photos',Page.photos.params['fid']+'-'+count);
				}
			}
			else {
				System.out.println('flibook does not match - must be a new flipbook');
				// set the count to one - because they have already seen an image
				System.cookie.set('vh1photos',Page.photos.params['fid']+'-1');
			}
		}
	}
}

Page.photos.init();



$j(Page.photos.loadSeriesModule);
//Page.onload('Page.photos.init');
//'photoGalleryTitle','content_main','content_title','imageContainer','image_info','relatedInfo'



/*
com.mtvi.ads.AdManager.adObject

javascript:com.mtvi.ads.AdManager.adObject.toString()


function (a_width, a_height, a_media, a_dartSite, a_gateway, a_pTileFlag, a_protocol, a_server, a_zone) { 
	this.adObjects[this.adObjects.length] = new this.adObject(a_width, a_height, a_media, a_dartSite, a_gateway, a_pTileFlag, a_protocol, a_server, a_zone); 
	com.mtvi.util.setProperties(this.adObjects[this.adObjects.length - 1]); 
	return this.adObjects[this.adObjects.length - 1]; }
	

	
	
	
	
function (a_width, a_height, a_media, a_dartSite, a_gateway, a_pTileFlag, a_protocol, a_server, a_zone) { 
	this.properties = {protocol:com.mtvi.util.isDefined(a_protocol) ? a_protocol : com.mtvi.ads.AdManager.getProtocol(), server:com.mtvi.util.isDefined(a_server) ? a_server : com.mtvi.ads.AdManager.getServer(), media:com.mtvi.util.isDefined(a_media) ? a_media : com.mtvi.ads.AdManager.getMedia(), dartSite:com.mtvi.util.isDefined(a_dartSite) ? a_dartSite : com.mtvi.ads.AdManager.getDartSite(), zone:com.mtvi.util.isDefined(a_zone) ? a_zone : com.mtvi.ads.AdManager.getZone(), width:com.mtvi.util.isDefined(a_width) ? a_width : "", height:com.mtvi.util.isDefined(a_height) ? a_height : "", gateway:com.mtvi.util.isDefined(a_gateway) ? a_gateway : "", gatewayOverride:com.mtvi.util.isDefined(a_gateway) ? true : false, uVal:"u=", pTileFlag:com.mtvi.util.isDefined(a_pTileFlag) ? a_pTileFlag : false, ord:com.mtvi.ads.AdManager.getOrdVal()}; 
	this.getTile = function () {
		com.mtvi.ads.AdManager.setTileCounter(com.mtvi.ads.AdManager.getTileCounter() + 1);
		return com.mtvi.ads.AdManager.getTileCounter();
	}; 
	this.getAdURL = function () {
		var retVal = "";
		var u_sections = "";
		var u_namesValues = "";
		retVal += this.getProtocol();
		retVal += this.getServer();
		retVal += "/" + this.getMedia();
		retVal += "/" + this.getDartSite() + com.mtvi.ads.AdManager.DART_SITE_DOMAIN;retVal += "/" + this.getZone() + ";";retVal += "pagename=" + com.mtvi.ads.AdManager.getPageName() + ";";if (this.getGatewayOverride() === false) {this.setGateway(com.mtvi.util.isDefined(com.mtvi.ads.AdManager.getSectionArray()) && com.mtvi.ads.AdManager.getSectionArray().length > 0 ? com.mtvi.ads.AdManager.getSectionArray()[0] : "");}retVal += "gateway=" + this.getGateway() + ";";for (var i = 1; i < com.mtvi.ads.AdManager.getSectionArray().length; i++) {retVal += "section_" + i + "=" + com.mtvi.ads.AdManager.getSectionArray()[i] + ";";u_sections += "|section_" + i + "-" + com.mtvi.ads.AdManager.getSectionArray()[i];}for (var i in com.mtvi.ads.AdManager.getNamesValuesObj()) {retVal += i + "=" + com.mtvi.ads.AdManager.getNamesValuesObj()[i] + ";";u_namesValues += "|" + i + "-" + com.mtvi.ads.AdManager.getNamesValuesObj()[i];}retVal += this.getUVal() + "|pagename-" + com.mtvi.ads.AdManager.getPageName();retVal += "|gateway-" + this.getGateway();retVal += u_sections;retVal += u_namesValues;retVal += ";";retVal += "sz=" + this.getWidth() + "x" + this.getHeight() + ";";retVal += this.getPTileFlag() === true ? "ptile=" + this.getTile() + ";" : "tile=" + this.getTile() + ";";retVal += "ord=" + this.getOrd() + "?";if (this.isOK() === false) {retVal = "";}return retVal;}; this.write = function () {var writeVal = "";try {if (this.isOK() === true) {if (self.location.search.indexOf("mockupMode=true") == -1) {writeVal += this.getTagOpen();}writeVal += this.getAdURL();if (self.location.search.indexOf("mockupMode=true") == -1) {writeVal += this.getTagClose();}}} catch (e) {try {com.mtvi.logger.JsError(e);return false;} catch (e) {return false;}}document.write(writeVal);}; this.getTagOpen = function () {var retVal = "";if (this.getMedia() == "adj") {retVal += "";} else if (this.getMedia() == "adi") {retVal += "\">";} else if (this.getMedia() == "ad") {retVal += "\"/>";}return retVal;}; this.isOK = function () {var retVal = true;if (!com.mtvi.util.isDefined(this.getZone())) {if (com.mtvi.ads.AdManager.getDebug() === true) {com.mtvi.debug("Error - Missing zone value in ad URL!");}retVal = false;}if (this.isSizeOK() === false) {if (com.mtvi.ads.AdManager.getDebug() === true) {com.mtvi.debug("Error - Wrong or missing size value in ad URL!");}retVal = false;}if (this.isMediaOK() === false) {if (com.mtvi.ads.AdManager.getDebug() === true) {com.mtvi.debug("Error - Wrong or missing media value in ad URL!");}retVal = false;}if (!com.mtvi.util.isDefined(this.getDartSite())) {if (com.mtvi.ads.AdManager.getDebug() === true) {com.mtvi.debug("Error - Missing dart site value in ad URL!");}retVal = false;}if (this.is_pTileFlagOK() === false) {if (com.mtvi.ads.AdManager.getDebug() === true) {com.mtvi.debug("Error - Wrong or missing pTile usage flag value in ad URL!");}retVal = false;}return retVal;}; this.is_pTileFlagOK = function () {var retVal = false;if (com.mtvi.util.isDefined(this.getPTileFlag()) && typeof this.getPTileFlag() == "boolean") {retVal = true;}return retVal;}; this.isMediaOK = function () {var retVal = false;var okMedia = new Array("ad", "adj", "adx", "pfadx", "adi");for (var i = 0; i < okMedia.length; i++) {if (this.getMedia() == okMedia[i]) {retVal = true;break;}}return retVal;}; this.isSizeOK = function () {var retVal = false;if (com.mtvi.util.isDefined(this.getWidth()) && !isNaN(this.getWidth()) === true && !isNaN(this.getHeight()) === true) {retVal = true;}return retVal;}; return this; }	


	*/
