jQuery.noConflict();
var last_clicked_btn = '';
var videoInLibrary = false;
var is_ad_global = 'no';
jQuery(document).ready(function(){
	if(getCurrentSection() == 'playlist' || getCurrentSection() == 'starred')
	{
		jQuery('#trash-btn').css({'background':'url('+IMAGE_PATH+'popplayer/trash_pl.png)'});
		jQuery('#trash-btn').mouseover(function(){
			jQuery(this).css({'background':'url('+IMAGE_PATH+'popplayer/trash_pl-hover.png)'});
		});		
		jQuery('#trash-btn').mouseout(function(){
			jQuery(this).css({'background':'url('+IMAGE_PATH+'popplayer/trash_pl.png)'});
		});				
	}
	
	
	jQuery('#continuous-button').bind('click',function(){
		if(jQuery('#continuous-button').attr('class') == 'disabled')
			return false;
			
		if(jQuery('#continuous-button').attr('class') == 'active')
		{
			jQuery('#continuous-button').removeClass('active');
			setPlaybackOption('');
			jQuery('#frmList div[hideable="true"]').fadeOut();
			jQuery('#frmList div[hideable="true"]').next().fadeOut();
		}
		else
		{
			jQuery('#player-options div').removeClass('active');		
			jQuery('#continuous-button').addClass('active');
			setPlaybackOption('continuous');
			//jQuery('#frmList div[youtube="false"]').css({'opacity':'0.5'});
			jQuery('#frmList div[hideable="true"]').fadeIn();
			jQuery('#frmList div[hideable="true"]').next().attr({'src':IMAGE_PATH+'popplayer/not_compatible_continuous.png'});
			jQuery('#frmList div[hideable="true"]').next().fadeIn();
		}
	});

	jQuery('#random-button').bind('click',function(){
		if(jQuery('#random-button').attr('class') == 'disabled')
			return false;
												   
		if(jQuery('#random-button').attr('class') == 'active')
		{
			jQuery('#random-button').removeClass('active');
			setPlaybackOption('');
			jQuery('#frmList div[hideable="true"]').fadeOut();
			jQuery('#frmList div[hideable="true"]').next().fadeOut();
		}
		else
		{												   
			jQuery('#player-options div').removeClass('active');
			jQuery('#random-button').addClass('active');
			setPlaybackOption('random');
			jQuery('#frmList div[hideable="true"]').fadeIn();
			jQuery('#frmList div[hideable="true"]').next().attr({'src':IMAGE_PATH+'popplayer/not_compatible_random.png'});
			jQuery('#frmList div[hideable="true"]').next().fadeIn();
		}
	});

	jQuery('#repeat-button').bind('click',function(){
		if(jQuery('#repeat-button').attr('class') == 'disabled')
			return false;
												   
		if(jQuery('#repeat-button').attr('class') == 'active')
		{
			jQuery('#repeat-button').removeClass('active');
			setPlaybackOption('');
			jQuery('#frmList div[hideable="true"]').fadeOut();
			jQuery('#frmList div[hideable="true"]').next().fadeOut();
		}
		else
		{												   												   
			jQuery('#player-options div').removeClass('active');
			jQuery('#repeat-button').addClass('active');
			setPlaybackOption('repeat');
			jQuery('#frmList div[hideable="true"]').fadeIn();
			jQuery('#frmList div[hideable="true"]').next().attr({'src':IMAGE_PATH+'popplayer/not_compatible_repeat.png'});
			jQuery('#frmList div[hideable="true"]').next().fadeIn();
		}
	});

	jQuery('.detail-btn').mouseover(function(){
		jQuery(this).addClass('detail-btn-hover');
	});
	jQuery('.detail-btn').mouseout(function(){
		if(jQuery('#std-screen-panelB').css('display') == 'none')
			jQuery(this).removeClass('detail-btn-hover');
	});

	jQuery('.share-btn').mouseover(function(){
		jQuery(this).addClass('share-btn-hover');
	});
	jQuery('.share-btn').mouseout(function(){
		if(jQuery('#share_box').css('display') == 'none')
			jQuery(this).removeClass('share-btn-hover');
	});

	jQuery('.detail-btn').click(function(){
		jQuery(this).addClass('detail-btn-hover');
		jQuery('#std-screen-panelB').slideToggle("slow",function(){
			if(jQuery('#std-screen-panelB').css('display') == 'none')
			{
				jQuery('.detail-btn').removeClass('detail-btn-hover');
				updateDetailbox('off');
			}
			else
			{
				updateDetailbox('on');
			}
		});
	});
	
	jQuery('.share-btn').click(function(){
		
		jQuery('#player_login').hide();
		
		jQuery(this).addClass('share-btn-hover');
		if(jQuery('#share_box').css('display') == 'none')
		{
			jQuery('#share_box').fadeIn("slow",function(){
				if(jQuery('#share_box').css('display') == 'none')
				{
					jQuery('.share-btn').removeClass('share-btn-hover');
					updateSharebox('off');
				}
				else
				{
					updateSharebox('on');
				}
			});
		}
		else
		{
			jQuery('#share_box').fadeOut("slow",function(){
				if(jQuery('#share_box').css('display') == 'none')
				{
					jQuery('.share-btn').removeClass('share-btn-hover');
					updateSharebox('off');
				}
				else
				{
					updateSharebox('on');
				}
			});		
		}
	});	

	jQuery('#pop-it-btn').click(function(){
		if(isLogin())
		{
			if(typeof(popedit) == 'function')
			{
				popedit(jQuery(".popd-count").text(),getPlayingVideo(),'yes','yes');
			}
			else if(typeof(popit) == 'function')
			{
				popit(getPlayingVideo());
			}
			popplayer_popit(getPlayingVideo());			
		}
		else
		{
			//close_player();
			//Set_Cookie('reloadplayer','yes',0,'/',COOKIE_DOMAIN,'');
			showLoginPanel();
		}
	});
	
	
	jQuery('#chatoff-btn').click(function(){
		updatePlayerChat('disable');
	});

	jQuery('#chaton-btn').click(function(){
		updatePlayerChat('enable');
	});

	
	jQuery('#trash-btn').click(function(){
		if(getCurrentSection() == 'playlist')
		{
			popplayer_remove_from_playlist(getPlayingVideo(),getPlaylistId());
		}
		else if(getCurrentSection() == 'starred')
		{
			popplayer_remove_from_starred(getPlayingVideo());
		}
		else
		{
			popplayer_remove_from_library(getPlayingVideo());
		}
	});
	
	jQuery('#undo').click(function(){
		popplayer_popit(getPlayingVideo());
		load_video_info(getPlayingVideo())
		pageload('');
	});
	
	jQuery('.cancelbtn').click(function(){		
		hideLoginPanel();
	});
	
	jQuery('#player_password').bind("keydown",function (e) {		
		if(e.which == 13)
		{
			var username = jQuery('#player_username').val();
			var password = jQuery('#player_password').val();
			playerLoginUser(username,password);			
		}
	});
	
	jQuery('.loginbtn').click(function(){
		var username = jQuery('#player_username').val();
		var password = jQuery('#player_password').val();
		playerLoginUser(username,password);
	});
	
	jQuery('.popd-count').click(function(){
		if(isLogin())
		{
			if(videoInLibrary == false)
			{
				popplayer_popit(getPlayingVideo());
			}
		}
		else
		{
			//close_player();
			//Set_Cookie('reloadplayer','yes',0,'/',COOKIE_DOMAIN,'');
			showLoginPanel();
		}
	});

	jQuery('#pop-it-btn').mouseover(function(){
		jQuery('.popd-count').addClass('popd-count-hover');
	});		

	jQuery('#pop-it-btn').mouseout(function(){
		jQuery('.popd-count').removeClass('popd-count-hover');
	});		

	jQuery("#std-screen-header").disableSelection();
		
	jQuery("#std-screen-header").bind("dblclick",minimizePlayer);
		
	player_drag_bind();
	
	jQuery('#browse-btn').click(function(){
		jQuery('#std-screen-panelB').toggle();
	});	
	
	jQuery('#lights-btn').click(function(){
		if(getPlayerLights() == 'on')
		{
			turnLightsOff();
			jQuery('.popd-count').removeClass('popd-count-hover');
			jQuery('.popd-count').addClass('popd-count-dark');
			updatePlayerLights('off')			
		}
		else
		{
			turnLightsOn();			
			if(videoInLibrary)
			{
				jQuery('.popd-count').addClass('popd-count-hover');
			}
			jQuery('.popd-count').removeClass('popd-count-dark');
			updatePlayerLights('on')
		}
	});
	
	jQuery('.playicon').click(function(){
		video_id_str = jQuery(this).attr('id');
		video_id_arr = (video_id_str).split('_');
		var video_id = video_id_arr[1];
		launchPopPlayer(video_id,false);
	});
		
	jQuery('#pop-player-std-close-btn').click(function(){
		close_player();
	});		

	jQuery('#pop-player-std-min-btn').click(function(){
		minimizePlayer();
	});		
	jQuery('#pop-player-std-max-btn').click(function(){
		minimizePlayer();
				
	});
	jQuery('#embed-button').click(function(){
		showEmbedCode();
				
	});
	jQuery('#infiniti-button').click(function(){
		showShortUrl();
				
	});
	jQuery('#embed-code-close').click(function(){
		close_embed_url();
				
	});
	

	jQuery(document).bind("keydown",function (e) {
		if(jQuery('#pop-player-std-screen-wrap').css('display') == 'block')
		{ 
			if(e.which==27)
			{
				close_player();
			}
			else if(e.which==38)
			{
				if(isPlayerMinimize())
				{
					minimizePlayer();
					return false;
				}
				
			}
			else if(e.which==40)
			{
				if(!isPlayerMinimize())
				{
					minimizePlayer();
					return false;
				}
				
			}
			else if(e.which==37)
			{
				previous_video();
			}
			else if(e.which==39)
			{
				next_video();
			}
		}
	});	
	
	jQuery("#next-btn").click(function(){
		next_video();
	});
	
	jQuery("#previous-btn").click(function(){
		previous_video();
	});
	
	jQuery('#wide-btn').click(function()
	{
		if(is_ad_global == 'no')
		{
			//loadingPlayer();
			setPlayerMinWidth('856');
			updatePlayerSize('widescreen');
			jQuery('#wide-btn').hide();
			jQuery('#standard-btn').show();
			resetPlayerPosition('widescreen');
			resetPlayerDimenssions('widescreen');
		}
	});
	
	jQuery('#standard-btn').click(function()
	{
		if(is_ad_global == 'no')
		{
			//loadingPlayer();
			setPlayerMinWidth('696');
			updatePlayerSize('standard');
			jQuery('#wide-btn').show();
			jQuery('#standard-btn').hide();
			resetPlayerPosition('standard');
			resetPlayerDimenssions('standard');
		}
	});
	
	jQuery('#player_username').click(function(){
		if(jQuery('#player_username').val() == 'Username')
			jQuery('#player_username').val('');
	});
	
	jQuery('#player_password_text').click(function(){
		jQuery('#player_password_text').hide();
		jQuery('#player_password').show();
		jQuery('#player_password').focus();
	});

	jQuery('#player_password_text').focus(function(){
		jQuery('#player_password_text').hide();
		jQuery('#player_password').show();
		jQuery('#player_password').focus();
	});

});
