var CCLPlogosproducto = {
	oneHoverOn: false,
	videoStarted: false,
    videoEnded: false,
    videoDuration: 0
};

CCLPlogosproducto.debug = function() {
	if(window.console){
		console.log( Array.prototype.slice.call(arguments) );
	}
};

CCLPlogosproducto.ops = {
	isIE: !!(document.all),
	
	addEvent: function(elem, event, fn) {
		if (window.attachEvent)
			elem.attachEvent('on'+event, fn);
		else if (window.addEventListener) {
			elem.addEventListener(event, fn, false);
		}
		else {
			CCLPlogosproducto.debug('Failed to addEvent '+event+' to '+(elem.id || elem));
		}
	},

	setVals: function(obj, vals, addPx) {
		for (var x in vals)
			if (vals.hasOwnProperty(x))
				if (vals[x] || vals[x]===0)
					obj[x] = (addPx && parseInt(vals[x])) ? parseInt(vals[x])+'px' : vals[x];
	},
	
	createElement: function(tag, opts) {
		var elem = document.createElement(tag.toUpperCase());
		if (opts) {
			if (typeof opts.styles == 'object') {
				this.setVals(elem.style, opts.styles, true);
				delete opts.styles;
			}
			this.setVals(elem, opts);
		}
		return elem;
	}, 
	
	extend: function(ns, obj) {
		if (!ns || !obj) return null;
		for (var x in obj)
			if (obj.hasOwnProperty(x)) ns.prototype[x] = obj[x];
	},
	
	addStyles: function(styleObj, id) {
		//if (id && document.getElementById(id)) return;
		var style = document.getElementById(id) || CCLPlogosproducto.ops.createElement('style', {
			'type': 'text/css',
			'id': id || null
		});
		document.getElementsByTagName('head')[0].appendChild(style);
		if (CCLPlogosproducto.ops.isIE) {
			style.styleSheet.cssText = this.parseRules(styleObj);
		} else {
			style.appendChild(document.createTextNode(this.parseRules(styleObj)));
		}
	},

	parseRules: function(rules) {
		var toWrite = '';
		for (var x in rules)
			if (rules.hasOwnProperty(x)) {
				toWrite += x+'{';
				var styles = rules[x];
				for (var y in styles)
					if (styles.hasOwnProperty(y))
						toWrite += y+':'+styles[y]+';'
				toWrite += '}\n';
			}
		return toWrite;
	},
	
	addExploreProductToTable: function(tbody, url, colNumber) {
		var tr = CCLPlogosproducto.ops.createElement('tr');
	  	tbody.appendChild(tr);
	  	var td = CCLPlogosproducto.ops.createElement('td');
	  	td.colSpan = colNumber;
	  	td.align = 'center';
	  	tr.appendChild(td);
	  	CCLPlogosproducto.ops.addExploreProductToElement(td, url)
	},
	
	addExploreProductToElement: function(target, url) {
	  	var div = CCLPlogosproducto.ops.createElement('div');
	  	div.id = "ccsInnerExploreProduct";
	  	target.appendChild(div);
		CCLPlogosproducto.loadLibrary(url);
	},
	
	createVideo: function(embedDivId, playerId, width, height, videoFile, previewImage) {
	      var so = new SWFObject("http://logo.cnetcontentsolutions.com//videos/cbsiUvp.swf", playerId, width, height, "9.0.124.0", "#FFFFFF");
	      so.addParam("wmode", "opaque");
	      so.addParam("quality", "high");
	      so.addParam("allowScriptAccess", "always");
	      so.addParam("allowFullScreen", "true");  
	      so.addVariable("autostart", "false");
	      so.addVariable("partner", "windemo");
	      so.addVariable("smode", "fit");
	      so.addVariable("file", "http://logo.cnetcontentsolutions.com//videos/" + videoFile);
	      if(previewImage) {
	        so.addVariable("thumbnail", "http://logo.cnetcontentsolutions.com//images/" + previewImage);
	      }
	      so.addVariable("uvpc", "http://logo.cnetcontentsolutions.com//videos/uvp_notrack.xml");
	      so.write(embedDivId);  
	},
	
	onContentStarted: function(playerId) { 
		CCLPlogosproducto.videoStarted = true;
		CCLPlogosproducto.videoEnded = false;
		CCLPlogosproducto.videoDuration = document.getElementById(playerId).getDuration() * 1000;
	},
			
	onContentEnded: function(playerId) {
		if(CCLPlogosproducto.videoStarted) {
			CCLPlogosproducto.videoEnded = true;
			var logo = document.getElementById(playerId.replace("CBSi-UVP-Player-", "CCLP")).parentLogo;
			if(logo) {
				logo.reportVideoEvent(CCLPlogosproducto.videoDuration);
			}
			CCLPlogosproducto.videoStarted = false;
		}
	}
};

CCLPlogosproducto.Logo = function(specs, options) {
	this.specs = specs;
	this.options = {};
	this.over = {
		logo: false,
		ad: false
	};
	this.timeout = false;
	if (!this.specs) {
		CCLPlogosproducto.debug('CCLPlogosproducto.Logo constructor: No specs sent for icon.');
		return;
	}
	this.setLogo();
	if (this.specs.logo.hasHoverHtml == 'true') {
		this.setInteraction('logo', this.specs.logo.closeHoverOnMouseOut == "true");
	}
	this.setOptions(options);
	return this.logoShell;
};

CCLPlogosproducto.ops.extend(CCLPlogosproducto.Logo, {
	setLogo: function() {
		if (!this.specs || !this.specs.logo || !this.specs.logo.src) {
			CCLPlogosproducto.debug('CCLPlogosproducto.Logo.setLogo: Specs problem. arguments: %o', arguments);
			return;
		}
		
		this.logoShell = CCLPlogosproducto.ops.createElement('div', {
			'className': 'CCLPlogo',
			styles: {
				'position': 'relative'
			}
		});
	
		this.logo = CCLPlogosproducto.ops.createElement('img', {
			'src': this.specs.logo.src,
			'alt': this.specs.logo.alt || null,
			'width': this.specs.logo.width || null,
			'height': this.specs.logo.height || null,
			styles: {
				'width': this.specs.logo.width,
				'height': this.specs.logo.height
			}
			
		});
		
		this.logoShell.appendChild(this.logo);
		return this;
	},
	
	getLogoCoords: function(obj){
		this.logoLeft = this.logoTop = 0;
				
		if (obj.offsetParent) {
			do {
				this.logoLeft += obj.offsetLeft;
				this.logoTop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
	},
	
	positionHover: function() {
		this.getLogoCoords(this.logo);
		
		CCLPlogosproducto.ops.setVals(this.ad.style, {
			'width': this.specs.ad.width,
			'height': this.specs.ad.height
		}, true);
		
		if(this.specs.ad.position == undefined) this.specs.ad.position = 'right';
		
		if(CCLPlogosproducto.ops.isIE){
			if(document.compatMode == 'CSS1Compat'){//doctype is valid
				var scrollTop = document.documentElement.scrollTop;
				var scrollLeft = document.documentElement.scrollLeft;
				
				var viewportHeight = document.documentElement.clientHeight - 8;
				var viewportWidth = document.documentElement.clientWidth - 8;
			}else{//doctype is NOT valid
				var scrollTop = document.body.scrollTop;
				var scrollLeft = document.body.scrollLeft;
				
				var viewportHeight = document.body.clientHeight - 8;
				var viewportWidth = document.body.clientWidth - 8;
			}
		}else{
			var scrollTop = window.pageYOffset;
			var scrollLeft = window.pageXOffset;
			
			var viewportHeight = window.innerHeight - 8;
			var viewportWidth = window.innerWidth - 8;
				
		}
		
		var popUpHeight = parseInt(this.ad.height)+4;
		var popUpWidth = parseInt(this.ad.width)+4;
		var protocol = window.parent.document.location.protocol;
		if (protocol == 'file:') { protocol = 'http:'; }
		var arrowUrl = protocol + '//logo.cnetcontentsolutions.com/images/';
		var border = 11;

		if(this.specs.ad.position == 'top' || this.specs.ad.position == 'bottom'){
			
			// Center of pop up should match center of logo horizontally...									
			var popUpLeft = (this.logoLeft - (popUpWidth/2)) + (this.logo.width/2);
			var popUpRight = popUpLeft + popUpWidth;

			// Adjust the pop up to be horizontally positioned within the viewport...
			if (popUpRight > scrollLeft + viewportWidth) {
				popUpLeft = scrollLeft + viewportWidth - popUpWidth;
			}
			// See above, but also, if viewport is smaller than pop up, then have the right side be off the screen...
			if (popUpLeft < scrollLeft) {
				popUpLeft = scrollLeft;
			}
			// Calc the position of the background arrow...
			var width_of_arrow = 12;
			var bkgPosition = (this.logoLeft - popUpLeft - width_of_arrow) + (this.logo.width/2);

			// Vertically position the pop up...
			var position;
			var popUpTop;
			// Figure out the top and bottom location if position = 'top'...
			var popUpBottomIfTop = this.logoTop;
			var popUpTopIfTop = popUpBottomIfTop - popUpHeight - border;
			// Figure out the top and bottom location if position = 'bottom'...
			var popUpTopIfBottom = this.logoTop + this.logo.height;
			var popUpBottomIfBottom = popUpTopIfBottom + popUpHeight + border;

			// Put the pop up on 'top' if it only fits on top...
			if (popUpTopIfTop >= scrollTop && popUpBottomIfBottom > scrollTop + viewportHeight) {
				position = 'top';
				var popUpTop = popUpTopIfTop;
			// Put the pop up on 'bottom' if it only fits on bottom...
			} else if (popUpTopIfTop < scrollTop && popUpBottomIfBottom <= scrollTop + viewportHeight) {
				position = 'bottom';
				var popUpTop = popUpTopIfBottom;
			// Otherwise, honor the customer preference...
			} else if (this.specs.ad.position == 'top') {
				position = 'top';
				var popUpTop = popUpTopIfTop;
			} else if (this.specs.ad.position == 'bottom') {
				position = 'bottom';
				var popUpTop = popUpTopIfBottom;
			}

			if (position == 'top') {
				//Position top
				CCLPlogosproducto.ops.setVals(this.hover.style, {
					'top': popUpTop,
					'left': popUpLeft,
					'background': 'url(' + arrowUrl + this.options.arrowOptions.topArrowPic + ') '+bkgPosition+'px bottom no-repeat',
					'paddingTop': 0,
					'paddingBottom': border 
				}, true);
			}else{
				//position bottom
				CCLPlogosproducto.ops.setVals(this.hover.style, {
					'top': popUpTop,
					'left': popUpLeft,
					'background': 'url(' + arrowUrl +  this.options.arrowOptions.bottomArrowPic + ') '+bkgPosition+'px top no-repeat',
					'paddingTop': border,
					'paddingBottom': 0 
				}, true);
			}
			
		}else if(this.specs.ad.position == 'left' || this.specs.ad.position == 'right'){
			this.hover.style.paddingTop = '0px';
			
			// Center of pop up should match center of logo vertically...									
			var popUpTop = (this.logoTop - (popUpHeight/2)) + (this.logo.height/2);
			var popUpBottom = popUpTop + popUpHeight;

			// Adjust the pop up to be Vertically positioned within the viewport...
			if (popUpBottom > scrollTop + viewportHeight) {
				popUpTop = scrollTop + viewportHeight - popUpHeight;
			}
			// See above, but also, if viewport is smaller than pop up, then have the bottom be off the screen...
			if (popUpTop < scrollTop) {
				popUpTop = scrollTop;
			}
			// Calc the position of the background arrow...
			var height_of_arrow = 12;
			var bkgPosition = (this.logoTop - popUpTop - height_of_arrow) + (this.logo.height/2);

			// Vertically position the pop up...
			var position;
			var popUpLeft;
			// Figure out the left and right location if position = 'left'...
			var popUpRightIfLeft = this.logoLeft;
			var popUpLeftIfLeft = popUpRightIfLeft - popUpWidth - border;
			// Figure out the left and right location if position = 'right'...
			var popUpLeftIfRight = this.logoLeft + this.logo.width;
			var popUpRightIfRight = popUpLeftIfRight + popUpWidth + border;

			// Put the pop up on 'left' if it only fits on left...
			if (popUpLeftIfLeft >= scrollLeft && popUpRightIfRight > scrollLeft + viewportWidth) {
				position = 'left';
				var popUpLeft = popUpLeftIfLeft;
			// Put the pop up on 'right' if it only fits on right...
			} else if (popUpLeftIfLeft < scrollLeft && popUpRightIfRight <= scrollLeft + viewportWidth) {
				position = 'right';
				var popUpLeft = popUpLeftIfRight;
			// Otherwise, honor the customer preference...
			} else if (this.specs.ad.position == 'left') {
				position = 'left';
				var popUpLeft = popUpLeftIfLeft;
			} else if (this.specs.ad.position == 'right') {
				position = 'right';
				var popUpLeft = popUpLeftIfRight;
			}

			if (position == 'left') {
				//Position left
				CCLPlogosproducto.ops.setVals(this.hover.style, {
					'top': popUpTop,
					'left': popUpLeft,
					'background': 'url(' + arrowUrl +  this.options.arrowOptions.leftArrowPic + ') right '+bkgPosition+'px no-repeat',
					'paddingRight': border, 
					'paddingLeft': 0
				}, true);
			}else{
				//position right
				CCLPlogosproducto.ops.setVals(this.hover.style, {
					'top': popUpTop,
					'left': popUpLeft,
					'background': 'url(' + arrowUrl +  this.options.arrowOptions.rightArrowPic + ') left '+bkgPosition+'px no-repeat',
					'paddingLeft': border,
					'paddingRight': 0 
				}, true);
			}
		}
	},

	createVideo: function(embedDivId, playerId, width, height, videoFile, previewImage) {
	      CCLPlogosproducto.ops.createVideo(embedDivId, playerId, width, height, videoFile, previewImage);  
	},
	
	closeVideo: function() {
	    var videoPlayer = document.getElementById("CBSi-UVP-Player-" + this.specs.logo.type + "-logosproducto");
	    if(videoPlayer) {
			this.reportVideoEvent(videoPlayer.getCurrentTime() * 1000);
			videoPlayer.clearVideo();
    	    CCLPlogosproducto.videoStarted=false;
    	    CCLPlogosproducto.videoEnded=false;
	    }
    },
    
    reportVideoEvent: function(duration) {
    	var reportUrl = "http://logo.cnetcontentsolutions.com//event/" + this.specs.logo.type + "?type=playVideo"
	        + "&responseLogoId=" + this.specs.logo.id
            + "&contractId=" + CCLPlogosproducto.details.partnerInfo.contractId
            + "&customerId=" + CCLPlogosproducto.details.partnerInfo.customerId
            + "&duration=" + duration;
        new Image().src = reportUrl;
    },
	
	setHover: function() {

		this.hover = CCLPlogosproducto.ops.createElement('div', {
			'className': this.options.classOptions.hoverClass,
			'id': "CCLP" + this.specs.logo.type + "-logosproducto"
		});

		this.hover.parentLogo = this;
		this.hover.startTime = 0;
		
		var outerDiv;
		if(this.specs.logo.type == "windowsClient" || this.specs.logo.type == "amdVision" || this.specs.logo.hoverType == "iframe") {
			var headerHeight = 25;
			var borderThickness = 2;
			var specAdHeight = this.specs.ad.height;
			if(this.specs.logo.closeHoverOnMouseOut == 'false') {
				specAdHeight = parseInt(this.specs.ad.height) + headerHeight + borderThickness/2;
			}
			outerDiv = CCLPlogosproducto.ops.createElement('div', {
				'className' :  "CCLPborder",
				'styles' : {
					'width' : this.specs.ad.width,
					'height' : specAdHeight
				}
			});
		} else {
			outerDiv = CCLPlogosproducto.ops.createElement('div', {
				'className' :  "CCLPborder",
				'width': this.specs.ad.height,
				'height': this.specs.ad.height
			});
		}

		this.hover.appendChild(outerDiv);
		if (this.specs.logo.type == "windowsClient" || this.specs.logo.type == "amdVision" || (this.specs.logo.hoverType == 'iframe' && this.specs.logo.closeHoverOnMouseOut == 'false')) {
			var headerStyle = (this.specs.logo.type == "windowsClient" || this.specs.logo.type == "neea" ) ? "CCLP_BrowserHeader_Grey" : "CCLP_BrowserHeader"
			var header = CCLPlogosproducto.ops.createElement('div', {
				'className' : headerStyle,
				'styles' : {
					'border-top':'1px solid #5b6370',
					'color':'#ffffff',
					'height':'25px',
					'margin':'0px',
					'overflow':'hidden',
					'padding':'0px',
					'position':'relative'
				}
			});
			var closeBtnImageName = (this.specs.logo.type == "windowsClient" || this.specs.logo.type == "neea" ) ? "close-gray.gif" : "close_btn.gif"
			var closebtn = CCLPlogosproducto.ops.createElement('div', {
				'className' : 'CCLP_BrowserClose',
				'styles' : {
					'background': 'url(http://logo.cnetcontentsolutions.com//images/' + closeBtnImageName + ') no-repeat right center',
					'cursor': 'pointer',
					'height': '20px',
					'marginTop':'2px',
					'marginRight':'10px',
					'padding': '0px',
					'position': 'absolute',
					'top': '0px',
					'right': '0px',
					'width': '20px'
				}
			});
			var titletext = CCLPlogosproducto.ops.createElement('div', {
				'className' : 'CCLP_BrowserTitle',
				'styles' : {
					'color': '#ffffff',
					'fontFamily': 'Arial, san-serif',
					'fontSize': '12px',
					'lineHeight': '23px',
					'margin': '0px auto 0px auto',
					'padding': '0px',
					'textAlign': 'center',
					'textShadow': '#000 1px 1px 0px',
					'width': '500px'
				}
			});
			var instance = this;
			CCLPlogosproducto.ops.addEvent(closebtn, "click", function() {
				instance.hideHover();
				if(instance.specs.logo.type == "gamespot") {
					instance.ad.parentNode.removeChild(instance.ad);
					instance.hover = null;
				}
			});
			header.appendChild(closebtn);
			header.appendChild(titletext);
			outerDiv.appendChild(header);
			if(this.specs.ad.title) {
				titletext.innerHTML = this.specs.ad.title;	
			}
		}

		outerDiv.appendChild(this.ad = CCLPlogosproducto.ops.createElement(this.specs.logo.hoverType, {
			'width': this.specs.ad.width,
			'height': this.specs.ad.height,
			'styles': {
				'background':'#FFF'
			}
		}));
		
		if(this.specs.logo.hoverType == "iframe") {
			this.ad.scrolling = 'no';
			this.ad.frameBorder = '0';
			this.ad.src = this.specs.ad.src;
		} else {
			outerDiv.id = this.options.classOptions.hoverClass + 'Div';
			outerDiv.padding = '0px !important';
			outerDiv.padding = 'none !important';
			this.ad.padding = '0px';
			this.ad.overflow = 'none';
			this.ad.innerHTML = this.specs.ad.innerHtml.replace(/~/g, "\""); 
		}
		
		document.body.appendChild(this.hover);
		this.setInteraction('hover', this.specs.logo.closeHoverOnMouseOut == "true");
		this.setInteraction('ad', this.specs.logo.closeHoverOnMouseOut == "true");
		
		/* NOTE: after the office hover html is loaded, we need to run the tabs scripts. The script won't work unless the html exists first in the DOM */
		if (this.specs.logo.type == "office2010" && this.specs.logo.hoverType == "div") {
			ccsjQuery('ul.CCLP_clickMe').tabs();
			ccsjQuery('ul.CCLP_clickMe');
		}
		
		if (this.specs.logo.type == "windowsServer" && this.specs.logo.hoverType == "div") {
			ccsjQuery('#CCLP_SERVER08_hoverContent ul').tabs();
			ccsjQuery(".CCLP_SERVER08_tableHilite tr").hover(
						function()
						{
							ccsjQuery(this).addClass("highlight");
						}, function()
						{
							ccsjQuery(this).removeClass("highlight");
						})
		} else if(this.specs.logo.type == "windowsClient") {
			CCLP_distributeTabWidths();
		} else if(this.specs.logo.type == "windows7-play") {
			this.createVideo("cbsiapiplayer", "CBSi-UVP-Player-windows7-play-logosproducto", "546", "476", "Intro.flv", "win7playto_preview.jpg");
		}
	},
	
	setInteraction: function(elem, closeOnMouseOut) {
		var instance = this;
		CCLPlogosproducto.ops.addEvent(this[elem], 'mouseover', function() {
			instance.over[elem] = true;
			if (instance.timeOut) clearTimeout(instance.timeOut);
			instance.timeOut = setTimeout(function(){instance.setDisplay.apply(instance, [elem, instance.over])}, 20);
		});
		if(closeOnMouseOut) {
		    CCLPlogosproducto.ops.addEvent(this[elem], 'mouseout', function() {
			    instance.over[elem] = false;
			    if (instance.timeOut) clearTimeout(instance.timeOut);
			    instance.timeOut = setTimeout(function(){instance.setDisplay.apply(instance, [elem, instance.over])}, 20);
		    });
		}
	},
	
	setDisplay: function(elem, over) {
		var show = false;
		for (var x in this.over) {			
			if (this.over.hasOwnProperty(x)) {
				if (this.over[x]){ 
					show = true;
					break;
				}
			}
		}
		if (!show) this.hideHover();
		else (this.showHover());
	},
	
	showHover: function() {
		if(CCLPlogosproducto.oneHoverOn)
		     return;
        CCLPlogosproducto.oneHoverOn = true;
        this.isHoverOn = true;

		if (!this.hover) {
			 this.setHover();
		}
		
		if (this.hover.startTime == 0)
			this.hover.startTime = new Date().getTime();
		this.positionHover();
		this.hover.style.display = 'block';
	},

	hideHover: function() {
		try {
			if(!this.isHoverOn)
			    return;
            this.isHoverOn = false;
            CCLPlogosproducto.oneHoverOn = false;
            
            if(CCLPlogosproducto.videoStarted) {
                this.closeVideo();
            }
            
			this.hover.style.display = 'none';
			this.logo.offsetParent.style.zIndex = 0;
			var duration = 0;
			if (this.hover.startTime != 0)
				duration =  new Date().getTime() - this.hover.startTime;
			this.hover.startTime = 0;
			var hoverTimeUrl;
			if(this.specs.logo.type == "gamespot") {
				hoverTimeUrl = this.getHoverEventUrl() + "&duration=" + duration;
			} else {
				hoverTimeUrl = this.specs.ad.src.replace("hoverhtml", "event") + "&type=hover&duration=" + duration;
			}
			
			new Image().src = hoverTimeUrl;
		} catch(e) {
			CCLPlogosproducto.debug('this.hover not yet created');
		}
	},
	
	getHoverEventUrl: function() {
		return "http://logo.cnetcontentsolutions.com//event/" + this.specs.logo.type 
		+ "?type=hover&responseLogoId=" + this.specs.logo.id
		+ "&contractId=" + CCLPlogosproducto.details.partnerInfo.contractId
		+ "&customerId=" + CCLPlogosproducto.details.partnerInfo.customerId;
	},

	setOptions: function(options) {
		this.options = options;
	}
});

CCLPlogosproducto.LogoShell = function(partData, logoData) {
	if (!partData || !logoData) {
		CCLPlogosproducto.debug('data incomplete');
		return null;
	}
	if (!partData.locationId || !document.getElementById(partData.locationId)) {
		CCLPlogosproducto.debug('target location not found');
		return null;
	}
	var shell = CCLPlogosproducto.ops.createElement('table', {
		'border': '0',
		'cellpadding': '0',
		'cellspacing': '0'
	});

	CCLPlogosproducto.ops.addStyles({
		'.CCLPpopup': {
			'position': 'absolute',
			'top': '0px',
			'left': '0px',
			'width':'auto',
			'height':'auto',
			'z-index': '500000 !important',
			'padding': '0px',
			'margin': '0px'
		},
		'.CCLPpopup div': {
		},
		'.CCLPpopup div iframe': {
			'border':'0',
			'margin': '0'
		},
		'.CCLPpopupWindows': {
				'position': 'absolute',
				'top': '0px',
				'left': '0px',
				'width':'auto',
				'height':'auto',
				'z-index': 10000,
				'padding': '0px',
				'margin': '0px'
		},
		'.CCLPpopupWindows div iframe': {
				'border':'0',
				'margin': '0'
	    },
	    '.CCLPpopupWindows .CCLPborder': {
	        'border':'2px solid black'
	    },
	    '.CCLPpopup .CCLPborder': {
	        'border':'2px solid #d7d8d7'
	    },
	    '.CCLPpopupBrowser': {
	        'height':'auto',
			'left':'0px',
			'margin':'0px',
			'padding':'0px',
			'position':'absolute',
			'top':'0px',
			'width':'auto',
			'z-index':'10000'
	    },
	    '.CCLPpopupBrowser iframe': {
	        'border':'0px',
			'margin': '0px',
			'padding': '0px'
	    },
	    '.CCLPpopupBrowser .CCLPborder': {
	        'border':'2px solid #000000',
			'padding':'0px'
	    }
	},'CCLPStyles');
	
	var tbody = CCLPlogosproducto.ops.createElement('tbody');
	shell.appendChild(tbody);
	
	var showLogos = [];
	for (var i=0; i<logoData.length; i++) {
		if (logoData[i].logo.success == 'true') showLogos.push(logoData[i]);
	}
	
	document.getElementById(partData.locationId).appendChild(shell);
	var cols = (partData.layout) ? partData.layout.split('x')[0]-0 : showLogos.length;
	var rows = (partData.layout) ? partData.layout.split('x')[1]-0 : 1;
	
	var ccInfo = CCLPlogosproducto.details.ccInfo;
	if ( ccInfo != null && (ccInfo.locationId == partData.locationId || !document.getElementById(ccInfo.locationId))) {
		CCLPlogosproducto.ops.addExploreProductToTable(tbody, ccInfo.url, cols);
	}
	
	for (var y=0, t=0; y<rows; y++) {
		var tr = CCLPlogosproducto.ops.createElement('tr');
		tbody.appendChild(tr);
		for (var x=0; x<cols; x++) {
			var td = CCLPlogosproducto.ops.createElement('td', {'align':'center', 'valign':'middle'});
			tr.appendChild(td);
			if (t < showLogos.length)
				if (showLogos[t].logo.type == 'windows7' || showLogos[t].logo.type == 'windows7-play' 
					|| showLogos[t].logo.type == 'office2010' 
					|| showLogos[t].logo.type == 'gamespot'
					|| showLogos[t].logo.type.indexOf("amd") == 0) {
					var hoverClassName = (showLogos[t].logo.type == 'gamespot' || showLogos[t].logo.type.indexOf("amd") == 0) ? 'CCLPpopupBrowser' : 'CCLPpopupWindows';
					td.appendChild(new CCLPlogosproducto.Logo(showLogos[t++], {
							arrowOptions : {
								rightArrowPic : 'cclpArrow_blck_right.gif',
								leftArrowPic : 'cclpArrow_blck_left.gif',
								topArrowPic : 'cclpArrow_blck_up.gif',
								bottomArrowPic : 'cclpArrow_blck_down.gif'
							}, 
							classOptions : {
								hoverClass : hoverClassName
							}
					}));	
				} else {
					td.appendChild(new CCLPlogosproducto.Logo(showLogos[t++], {
							arrowOptions : {
								rightArrowPic : 'cclpArrow_right.gif',
								leftArrowPic : 'cclpArrow_left.gif',
								topArrowPic : 'cclpArrow_up.gif',
								bottomArrowPic : 'cclpArrow_down.gif'
							},
							classOptions : {
								hoverClass : 'CCLPpopup'
							}
							
					}));
				}
			
		}
	}
};

	CCLPlogosproducto.loadLibrary = function(file, callback) {
	  var head      = document.getElementsByTagName('head')[0];
	  var script    = document.createElement('script');
	  script.type   = 'text/javascript';
	  script.src    = file;
	  if (callback)
		  script.onload = script.onreadystatechange = function() {
		    // execute dependent code
		    if (window.ActiveXObject &&  this.readyState != 'loading' ) {
		    	callback();
		    	script.onload = script.onreadystatechange = null;
		     } else if (! window.ActiveXObject) {
		    		callback();
		    	}
	
		  };
	  head.appendChild(script);
	}

	CCLPlogosproducto.loadExternalCSS = function(file) {
	  var head  = document.getElementsByTagName('head')[0];
	  var link  = document.createElement('link');
	  link.type = 'text/css';
	  link.href = file;
	  link.rel	= 'stylesheet';
	  head.appendChild(link);
	}
	
	CCLPReporting = function(event, logoProgram, logoResponseId, crossSaleProduct, qty) {

		if (qty==undefined)
			qty = 1;
		
		var reportUrl = "http://logo.cnetcontentsolutions.com//event/" + logoProgram + "?type="
					+ event
					+ "&crossSale="
					+ crossSaleProduct
					+ "&crossSaleQuantity="
					+ qty
					+ "&responseLogoId=" + logoResponseId
					+ "&contractId=" + CCLPlogosproducto.details.partnerInfo.contractId
					+ "&customerId=" + CCLPlogosproducto.details.partnerInfo.customerId
					+ "&unique="+ new Date().getTime();
			
		
		new Image().src = reportUrl;
		CCLPlogosproducto.wait(100);
			
	    return true;
	}
	
	CCLPlogosproducto.wait = function(msecs)
	{
		var start = new Date().getTime();
		var cur = start
		while(cur - start < msecs)
		{
			cur = new Date().getTime();
		}	
	}  
	
	var ccsjQuery;
	var jsReady = false;
	
	function setJSReady() {
		jsReady = true;
	}
	
	function isJSReady() {
		return jsReady;
	}
					
	function onCanPlayerReady(playerId) {
	      var cbsiPlayer = document.getElementById(playerId); 
	      var locationId = playerId.substr(playerId.lastIndexOf("-") + 1);
		  cbsiPlayer.addEventJSCallback("onContentStart_cbsi", "CCLP" + locationId + ".ops.onContentStarted");
		  cbsiPlayer.addEventJSCallback("onContentEnd_cbsi", "CCLP" + locationId + ".ops.onContentEnded");
	}	
	
    function closeWindows7PlayVideoHover() {
    	document.getElementById("CCLPwindows7-play-logosproducto").parentLogo.hideHover();
	}

    function CCLPLoadJQueryLibrary(callback) {
    	CCLPlogosproducto.loadLibrary('http://logo.cnetcontentsolutions.com//scripts/jquery.min.js',
    			function() {
    				CCLPlogosproducto.loadLibrary('http://logo.cnetcontentsolutions.com//scripts/ui.core.min.js', function() {
    					CCLPlogosproducto.loadLibrary('http://logo.cnetcontentsolutions.com//scripts/ui.tabs.min.js', function() {
    						ccsjQuery = $.noConflict(true);
    						callback();
    					});
    				});
    		});
    }

CCLPlogosproducto.details = {partnerInfo : {"customerId":"2814","layout":"3x1","locationId":"logosproducto","contractId":"4463"},logos : [{"logo":{"id":1042,"closeHoverOnMouseOut":"true","hasHoverHtml":"true","height":"67","alt":"","hoverType":"iframe","width":"58","src":"http://logo.cnetcontentsolutions.com/s/AS00000000000000000343es.png?customerId=2814&contractId=4463&logoType=alascore&responseLogoId=1042&productId=8527909&h=043ab21f&cds=S6050181&locale=es&style=1&layout=3x1&locationId=logosproducto","type":"alascore","success":"true"},"ad":{"position":"right","height":"250","width":"300","src":"http://logo.cnetcontentsolutions.com/hoverhtml/alascore?&productId=8527909&customerId=2814&contractId=4463&logoType=alascore&responseLogoId=1042&logoLevel=&h=043ab21f&cds=S6050181&locale=es&style=1&layout=3x1&locationId=logosproducto"}}]
};

CCLPlogosproducto.ops.addEvent(window,'load', function() {
	
    var loadCCLPJQuery = false;
    var cclpLoadSwfJs = false;
	if (CCLPlogosproducto.details.logos) {
		for (var i=0; i<CCLPlogosproducto.details.logos.length; i++) {
			var logo = CCLPlogosproducto.details.logos[i].logo;
			if (logo.type == "windows7-play") {
				cclpLoadSwfJs = true;
			} else if(logo.hoverType == "div" && logo.type == "office2010") {
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/office2010_div.css');
				loadCCLPJQuery = true;
			} else if(logo.hoverType == "div" && logo.type == "windowsServer") {
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/server2008_div.css');		
				loadCCLPJQuery = true;
			} else if(logo.hoverType == "div" && logo.type == "officeHover") {
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/office2007_div.css');		
				loadCCLPJQuery = false;
			} else if(logo.type == "gamespot") {
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/CCLP_browser.css');
			} else if(logo.type == "windowsClient") {
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/CCLP_browser.css');
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/windowsClient_div.css');
				CCLPlogosproducto.loadLibrary('http://logo.cnetcontentsolutions.com//scripts/ccs_tabs.js');
			} else if(logo.type == "amdVision") {
				cclpLoadSwfJs = true;
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/CCLP_browser.css');
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/amd_vision.css');
				CCLPlogosproducto.loadLibrary('http://logo.cnetcontentsolutions.com//scripts/amd_vision.js');
			} else if(logo.type == "amdCpu" || logo.type == "amdGpu" || logo.type == "neea" || logo.type == "windowsServer") {
				CCLPlogosproducto.loadExternalCSS('http://logo.cnetcontentsolutions.com//styles/CCLP_browser.css');
			}
		}
	} 
	
	if(CCLPlogosproducto.details.ccInfo != null) {
		var details = CCLPlogosproducto.details;
		var ccLocationId = document.getElementById(details.ccInfo.locationId);
		if(!details.logos) {
			if(!ccLocationId && details.partnerInfo != null && details.partnerInfo.locationId != null)
				ccLocationId = document.getElementById(details.partnerInfo.locationId);
			if(!ccLocationId) {
				CCLPlogosproducto.debug("ExplorePrduct location not found");
			} else 
				CCLPlogosproducto.ops.addExploreProductToElement(ccLocationId, details.ccInfo.url);
		} else if(ccLocationId != null && details.ccInfo.locationId != details.partnerInfo.locationId)
			CCLPlogosproducto.ops.addExploreProductToElement(ccLocationId, details.ccInfo.url);
	}
	
	if(cclpLoadSwfJs) {
		setJSReady();
		CCLPlogosproducto.loadLibrary('http://logo.cnetcontentsolutions.com//scripts/swfobject.js');
	}
	
	if(loadCCLPJQuery) {
		CCLPLoadJQueryLibrary(function() {
						CCLPlogosproducto.LogoShell(CCLPlogosproducto.details.partnerInfo, CCLPlogosproducto.details.logos);
					});
	} else if (CCLPlogosproducto.details.logos) {
		CCLPlogosproducto.LogoShell(CCLPlogosproducto.details.partnerInfo, CCLPlogosproducto.details.logos);
	}
	
});



