/* ---------------------------------
  @ youtube video manager
----------------------------------- */
function videoManager( thumbnails, popup, items ) { this.init(thumbnails, popup, items) };

videoManager.prototype = {

	init : function( thumbnails, popup, items )
	{
		if (thumbnails != undefined && popup != undefined && items != undefined) {
			
			// set refs to elements
			this.thumbnails = thumbnails;
			this.popup = popup;
			
			// set up thumbnails
			var self = this;
			$.each(
				items,
				function(i, item) {
					var elem = $(self.thumbnails[i]);
					
					// get link
					var data = item["media:group"];
					
					// parse json data
					var title = data["media:title"];
					var thumbnail = data["media:thumbnail"][0];
					var link = data["media:content"][0].url;
					
					elem
						.attr('src', thumbnail.url)
						.attr('width', 130)
						.attr('height', 97)
						.parent()
							.attr('href', 'javascript:void(null);')
							.attr('title', 'Watch Video')
							.click(function() {
							
								// open the link
								self.open(link);
								
								/* omniture
								var s=s_gi('ascanceautopartslive');
								s.linkTrackVars='events,eVar11,channel,hier1,prop1';
								s.linkTrackEvents='event10';
								s.events='event10';
								s.eVar11=title.content;
								s.channel='Cruz Blog';
								s.hier1='Cruz Blug, Videos';
								s.prop1=title.content;
								s.tl(this,'o', title.content);
								*/
								
							});
							
					/*
					
					*/
				});
			
			// close button
			var self = this;
			overlayMgr.elem
				.click( function() {
					self.close();
				});
			
		} else {
			log('Cannot initialize');
		};
	},
	
	open : function( link )
	{
		// if data is not null, activate it
		if (link != null && link != undefined) {
			
			var self = this;
			
			// set open flag
			this.isopen = true;
			
			// set panel x-position
			this.resetPanelX();
			this.resetPanelY();
			
			// build the innerHTML
			var video = "<object width='425' height='344'><param name='movie' value='"+ link +"&hl=en&rel=0&color1=0xe1600f&color2=0xfebd01'></param><embed src='"+ link +"&hl=en&rel=0&color1=0xe1600f&color2=0xfebd01' type='application/x-shockwave-flash' width='425' height='344'></embed></object>";
			this.popup.html(video);
			
			// show overlay overtop of mystroller widget tab
			overlayMgr.show();
			
			// fade in panel
			this.popup.show();
		
		};
	},
	
	close : function()
	{
		overlayMgr.hide();
		this.popup.empty().hide();
		
		// set flag
		this.isopen = false;
	},
	
	getPanelX : function() { return ( ($('#ui').width()/2) - (this.popup.width()/2) ) },
	setPanelX : function( x ) { this.popup.css('left', x) },
	
	getPanelY : function()
	{
		// current scrollPosition
		var sT = $(window).scrollTop();
		var vH = $(window).height();
		
		// set target y
		return (sT + (vH/2) - (this.popup.height()/2));
	},
	setPanelY : function( y ) { this.popup.css('top', y) },
	
	resetPanelX : function() { this.setPanelX( this.getPanelX() ) },
	resetPanelY : function() { this.setPanelY( this.getPanelY() ) }
	
};

