var $video=jQuery.noConflict();

function reduceVideoToSmallSize(){
	var largePlayer = $video('#video');
	if(largePlayer == null || largePlayer == undefined)
		return;
	
	videoHolder = $video('.videoHolder');
	if(videoHolder == null || videoHolder == undefined)
		return;
	
	videoHolder.removeClass("videoPlay");
	largePlayer.removeClass("largeVideo");
}

function play() {
	
	var videoToDisplay = $video('#myytplayer');
	
	var videoUrl;
	
	if(videoToDisplay == null || videoToDisplay == undefined)
		return;
	
	if((window.location.protocol) == "https:") {
		videoUrl = $video(videoToDisplay).attr('src');
		videoUrl = videoUrl + '&autoplay=1';
		videoToDisplay.attr('src', videoUrl);
	} else {
		videoUrl = $video(videoToDisplay).attr('data');
		videoUrl = videoUrl + '&autoplay=1';
		videoToDisplay.attr('data', videoUrl);
		var videoContainer =  $video('#video');
		
		if(videoContainer == null || videoContainer == undefined)
			return;
		
		videoContainer.empty();
		videoContainer.append(unescape("%3Cobject id='myytplayer' type='application/x-shockwave-flash' data='"+ videoUrl +"' %3E%3Cparam name='movie' value='" + videoUrl + "'%3E%3C/param%3E%3Cparam name='allowFullScreen' value='false'%3E%3C/param%3E%3Cparam name='allowscriptaccess' value='always'%3E%3C/param%3E%3Cparam name='wmode' value='opaque'%3E%3C/param%3E%3Cparam name='type' value='application/x-shockwave-flash'%3E%3C/param%3E%3C/object%3E"));
	}

	var screenshot = $video('#screenshotArea');
	if(screenshot == null || screenshot == undefined)
   		return;

	var hideVideoPlay = $video('span.hideVideoPlay');
	if(hideVideoPlay == null || hideVideoPlay == undefined)
   		return;
	
	// hide video screenshot preview
	screenshot.css('display','none');
	hideVideoPlay.css('display','none');
	
	videoToDisplay = $video('#video');
	if(videoToDisplay == null || videoToDisplay == undefined)
		return;
	
	videoHolder = $video('.videoHolder');
	if(videoHolder == null || videoHolder == undefined)
		return;
	
	videoHolder.addClass("videoPlay");
	videoToDisplay.addClass("largeVideo");
    	
    hideVideo();
    
}

function resizeToLargeVideo() {
	videoToResize = $video('#video');
	if(videoToResize == null || videoToResize == undefined)
		return;
	
	videoHolder = $video('.videoHolder');
	if(videoHolder == null || videoHolder == undefined)
		return;
	
	videoHolder.addClass("videoPlay");
	videoToResize.addClass("largeVideo");
	
    hideVideo();
}

function hideVideo()
{
	$video(document).unbind('click');
	$video(document).bind('click',function (e){	
			var target = e.target || e.srcElement;
			var selectTarget = $video(target);
			
			if(selectTarget.is('span.hideVideoPlay') || selectTarget.is('span.resizeToLargeVideo') || selectTarget.is('object#myytplayer') || selectTarget.is('iframe#myytplayer'))
				return;
			else
			{
				reduceVideoToSmallSize();
				$video(document).unbind('click');
			}
	});
	
}

