// JavaScript Document

VideoAndMedia = function()
{
	//this.categories_navigation_bar_HTMLObject = null;
	//this.videos_main_box_HTMLObject = null;
	//this.processorUrl = null;
		
	this.waitForImage = function(loading_image, thumbnail_image, stepDuration)
	{
		var loading_image_html_object = YAHOO.util.Dom.get(loading_image);
		var thumbnail_image_html_object = YAHOO.util.Dom.get(thumbnail_image);
		//alert(thumbnail_image_html_object);
		if(!thumbnail_image_html_object.complete)
		{
			var _this = this;
			setTimeout(function() { _this.waitForImage(loading_image, thumbnail_image, stepDuration) }, stepDuration);
			//setTimeout("waitForMainImage("+"\""+alt+"\")", 250);
		}
		else
		{
			YAHOO.util.Dom.removeClass(loading_image_html_object.id, 'elementVisible');
			YAHOO.util.Dom.addClass(loading_image_html_object.id, 'elementHidden');
			YAHOO.util.Dom.removeClass(thumbnail_image_html_object.id, 'elementHidden');
			YAHOO.util.Dom.addClass(thumbnail_image_html_object.id, 'elementVisible');

			vcElementImage = thumbnail_image_html_object.parentNode;
			
			YAHOO.util.Event.addListener(vcElementImage.id, "mouseover", this.mouse_over_vcElement);
		}
	}
	

	this.replaceImage = function(loading_image)
	{
		//Generate id for loading image
		YAHOO.util.Dom.generateId(loading_image,"loading_image_");
		//Get the next sibling for loading image
		var thumbnail_image = YAHOO.util.Dom.getNextSibling(loading_image);
		//Generate id for the next sibling (thumbnail_image)
		YAHOO.util.Dom.generateId(thumbnail_image,"thumbnail_image_");
		//Replace loading image for thumbnail image
		var stepDuration = 250;
		this.waitForImage(loading_image.id, thumbnail_image.id, stepDuration);

	}
	
	this.loading_images = function()
	{
		var loading_images  = YAHOO.util.Dom.getElementsByClassName('elementVisible',"img","",this.replaceImage,this,true);	
	}

	this.videoTitleMouseOut = function(e, obj)
	{
		var descriptionContainer  = obj.descriptionContainer;
		var videoTiltleLink = YAHOO.util.Dom.getFirstChild(descriptionContainer);
		YAHOO.util.Dom.replaceClass(videoTiltleLink.id, 'videoTitleMouseOver','videoTitle');
	}
	
	this.videoTitleMouseOver = function(e, obj)
	{
		var descriptionContainer  = obj.descriptionContainer;
		var videoTiltleLink = YAHOO.util.Dom.getFirstChild(descriptionContainer);
		YAHOO.util.Dom.replaceClass(videoTiltleLink.id, 'videoTitle','videoTitleMouseOver');
	}
	
	this.videoCellsFormatter = function()
	{
		var videoCells = YAHOO.util.Selector.query('div.videoCell','videos_main_box');
		for(i=0; i<videoCells.length; i++)
		{
			
			var imageContainer = YAHOO.util.Dom.getFirstChild(videoCells[i]);
			var descriptionContainer = YAHOO.util.Dom.getLastChild(videoCells[i]);
			var obj = {
				descriptionContainer: descriptionContainer
			};
			YAHOO.util.Event.addListener(imageContainer, "mouseover", this.videoTitleMouseOver, obj, this);
			YAHOO.util.Event.addListener(imageContainer, "mouseout" , this.videoTitleMouseOut,  obj, this);
		}
		this.loading_images();
	}


	this.init = function()
	{	
		this.videoCellsFormatter();
	}
	
};
