/*
    Document   : main.js
    Created on : 31.07.2009, 15:57:38
    Author     : Artem Kiselev aka hemantic / modified by Waldes

*/

$(document).ready(function(){
	$("#topmenu .menu-secondlevel").each(function(){
		$(this).find("li:last").addClass("last");
	});

	$(".doublecol").each(function(){
		$(this).find(".article:last").addClass("last");
	});
	
	$("#topmenu>li").hover(
		function(){
			$(this).addClass("active");
		},
		function(){
			$(this).removeClass("active");
		}
	);

	$(".rating .article").hover(
		function(){
			$(this).find(".g-controls").show();
		},
		function(){
			$(this).find(".g-controls").hide();
		}
	);

	//Mainplayer playlist comments link
	if($(".playlist .clips a span")[0]){
		$(".playlist .clips a span").click(function() {
			$('#playlist-blocker').show();
			document.location.href=$(this).parent().find("em").html();
			return false;
		});
	}
	
	
	var mainplayer_settings = {
		key: '@f862a6188dc6644e225',

		logo: {
			url: 'http://static.gameslife.ru/images/player_logo.png',
			fullscreenOnly: false,
			top: 8,
			right:5,
			linkUrl: 'http://gameslife.ru'
		},

		//onMouseOver: function() {
		//	var sclip = this.getClip();
		//		if(sclip.isInStream){
		//			return this.getPlugin("content").css({backgroundImage: 'http://kanobu.ru/media/kanobu/modern/images/partners/logo_lava.png'}).fadeIn(1000);
		//		}	
    	//	}, 
				
		//onMouseOut: function() { 
		//	this.getPlugin("content").fadeOut(1000)
    	//	},

		clip: {

			tags: ['gl'],

			scaling:'fit',
			
			onStart: function(clip) {
				pageTracker._trackEvent("Videos", "Play", clip.url);
				$('#embedTab').removeClass("inactive");
			},

			onFinish: function(clip) {
				pageTracker._trackEvent("Videos", "Finish", clip.url);
			}
		},				

		canvas: {
			backgroundColor: '#000000',
			backgroundGradient: 'none'
		},

		play: {
			opacity: 1,
			label: null,
			replayLabel: 'Ещё раз'
		},

		plugins: {

			videoplaza: {
				url: 'http://service.cdn.videoplaza.com/resources/as3_bridge_flowplayer.swf',

				vpid:'9f03e736-81c3-4943-8bc4-fabbf4593f73'
			},
			
			vn:  { 
           		url: 'http://poligon.videonow.ru/players/plugins/vn_flowplayer_plugin.swf',
				vn_profile_id: 95281, //id профиля
				vn_category_id: 7, //id категории видео 
				top: 0, 
            	left: 0 
        	},

			controls: {
				url: 'http://gameslife.ru/flowplayer/flowplayer.controls-skinless-3.1.5.swf',
				skin: 'customskin',
				fullscreen:true,
				backgroundGradient: 'none',
				backgroundColor: 'transparent',
				border: 'none',
				
				hideDelay: 1000,

				all:false,
				
				enabled: {scrubber: true},
				
				scrubber:true,
				volume:true,
				play:true,
				mute:true,
				playlist:false,
				height: 30,
				autoHide: 'always',
				bottom: 5,
				left: '50%'
			},

			customskin: {
				url: "http://gameslife.ru/flowplayer/gameslife_buttons.swf",
				type: "classLibrary"
			}//,
			
			//content: {  
            //       		url: 'http://gameslife.ru/flowplayer/flowplayer.content-3.1.0.swf', 
 
            //        		display: 'block', 
            //     		backgroundGradient: 'none', backgroundColor: 'transparent', border: 0,  
			//	backgroundImage: 'http://static.kanobu.ru/kanobu/modern/images/adv/overlay_mass2.swf',
				
            //     		top: 0, left: 4,  width: 200, height: 75//,		
			//}
		}

	};
	
	
	var player_settings = {
		key: '@f862a6188dc6644e225',

		logo: {
			url: 'http://static.gameslife.ru/images/player_logo.png',
			fullscreenOnly: false,
			top: 8,
			right:5,
			linkUrl: 'http://gameslife.ru'
		},

		clip: {

			tags: ['gl'],

			scaling:'fit',
			autoPlay: true,
			autoBuffering: false,
			
			onStart: function(clip) {
				$('#embedTab').removeClass("inactive");
				pageTracker._trackEvent("Videos", "Play", clip.url);
				$('#embedTab').removeClass("inactive");
			},
			onFinish: function(clip) {
				pageTracker._trackEvent("Videos", "Finish", clip.url);
			}
		},

		canvas: {
			backgroundColor: '#000000',
			backgroundGradient: 'none'
		},

		play: {
			opacity: 1,
			label: null,
			replayLabel: 'Ещё раз'
		},

		plugins:  {

			videoplaza: {
				url: 'http://service.cdn.videoplaza.com/resources/as3_bridge_flowplayer.swf',
				vpid:'9f03e736-81c3-4943-8bc4-fabbf4593f73'
			},
			
			vn:  { 
            	url: 'http://poligon.videonow.ru/players/plugins/vn_flowplayer_plugin.swf',
				vn_profile_id: 95281, //id профиля
				vn_category_id: 7, //id категории видео 
				top: 0, 
            	left: 0 
        	},

			controls: {
				url: 'http://gameslife.ru/flowplayer/flowplayer.controls-skinless-3.1.5.swf',
				skin: 'customskin',

				fullscreen:true,
				backgroundGradient: 'none',
				backgroundColor: 'transparent',
				border: 'none',
				
				hideDelay: 1000,

				all:false,
				scrubber:true,
				volume:true,
				play:true,
				mute:true,
				playlist:false,

				height: 30,

				autoHide: 'always',

				bottom: 5,
				left: '50%'
			},
			customskin: {
				url: "http://gameslife.ru/flowplayer/gameslife_buttons.swf",
				type: "classLibrary"
			}//,
			
			//content: {  
            //     		url: 'http://gameslife.ru/flowplayer/flowplayer.content-3.1.0.swf', 
 
             //   		display: 'block', 
          
             //   		backgroundGradient: 'none', backgroundColor: 'transparent', border: 0,  
			//	backgroundImage: 'http://static.kanobu.ru/kanobu/modern/images/adv/overlay_mass2.swf',
			
			//	top: 0, left: 4,  width: 200, height: 75,

			//	onClick: function() {
			
			//		pageTracker._trackEvent("Videos", "Overlay", "http://kanobu.ru/blog/id17776/");
			//	}
			//}
		}
	};

	if($("a.player_centered")[0]){
		$f("a.player_centered", {src: "http://gameslife.ru/flowplayer/flowplayer.commercial-3.1.5.swf", wmode: 'opaque'}, player_settings);
		$(".player_centered").show();
		//$("#embedPane textarea").html($f(".player_centered").embed().getEmbedCode());
//		var code = $f().embed().getEmbedCode();
	}
	
	
	if($("#player_main")[0]){
		$(".playlist").scrollable({size: 3,next:'a.next',prev:'a.prev'});

		$(".clips a").click(function() {
        	$(this).fadeOut().fadeIn();
//			return false;
    	});

		$f("player_main", {src: "http://gameslife.ru/flowplayer/flowplayer.commercial-3.1.5.swf", wmode: 'opaque'}, mainplayer_settings).playlist("div.mainplayer", {scaling:'fit', loop:false});
	}
	
});



$(function() {
	var reEmbed = new RegExp(".*EMBED.*");
	var reDownload = new RegExp(".*DOWNLOAD.*");
	var reLicensed = new RegExp(".*LICENSED.*");
	$('.embedTabClass').click(function(){
                // rel - id плеера
                // rev - содежит комбинацию EMBED, DOWNLOAD, LICENSED по 
		// наличию этого определяется какие ссылки должны быть активны
                var embedTab = $(this);
		if (!embedTab.attr('rev').match(reEmbed)) {
			embedTab.css('display', 'none');
			$(embedTab.attr('id')+'Dis').css('display', 'inline');
			return false;
		} else {
			embedTab.css('display', 'inline');
			$(embedTab.attr('id')+'Dis').css('display', 'none');
		}
                var player_id = embedTab.attr('rel');
		if ($('#'+player_id)[0]) {
	                f_player = flowplayer(player_id);
		} else {
	                f_player = flowplayer(0);
		}
		embedTab.removeClass("inactive");
		if(!embedTab.attr('rev').match(reEmbed)) {
			f_player.play();
		} else {
			$("#player_actions a").removeClass("active");
			embedTab.addClass("active");
			var embedPane = $(embedTab.attr("href"));
			embedPane.show();
//			$('#emailPane').hide();
			$('#playlist-blocker').show();
			var clipPreview = $("#currentClipPreviewImg").html();
			//var embedCode = f_player.embed().getEmbedCode();
			
			var embedCode = EMBED(
				$('#player_main img').attr('src') || $('#pl1 img').attr('src'),
				$('.clips.items a.active').attr('href') || $('.clips.items a.first').attr('href') || $('.player.player_centered').attr('href')
			);
			
			/*
			embedCode = embedCode.replace('"playlist":[{"scaling":"fit"','"playlist":[{"controls":{"scrubber":false,"volume":false,"fullscreen":false,"play":false,"mute":false},"url":"'+clipPreview+'"},{"autoPlay":false,"scaling":"fit"');
			embedCode = embedCode.replace('"play":{"opacity":1,"label":null,"replayLabel":"Ещё раз"}','"play":{"width":600,"height":400,"opacity":0}');
			embedCode = embedCode.replace('"autoPlay":false,"scaling":"fit","autoPlay":true','"autoPlay":false,"scaling":"fit"');
			
			embedCode = embedCode.replace(/"scaling":"fit"/g, '"scaling":"fit","autoPlay":false');
			//embedCode = embedCode.replace(/"vn":\{.*\},/g, '');
			
			embedCode = embedCode.replace('"playlist":[', '"playlist":[{"controls":{"scrubber":false,"volume":false,"fullscreen":false,"play":false,"mute":false},"autoPlay":true,"url":"'+($('#player_main img').attr('src') || $('#currentClipPreviewImg').html())+'"},')
			
                        try {
				if($(".playlist a.first").length) {
					embedCode = embedCode.replace(new RegExp($(".playlist a.first").attr("href").toString(), "g"),$(".playlist a.playing").attr("href").toString());
				}
			} catch(e) {};
      */

			//document.getElementById("clipEmbedCode").innerHTML = embedCode;
			$("#"+embedPane.attr('id')+" .item:first").html('<textarea id="clipEmbedCode" class="embed-text input-text" onfocus="this.select()">'+embedCode+'</textarea>');
		}
		return false;
	});

	$('.downloadTabClass').click(function(){
                var downloadTab = $(this);
		if (!downloadTab.attr('rev').match(reDownload)) {
			downloadTab.css('display', 'none');
			$(downloadTab.attr('id')+'Dis').css('display', 'inline');
			return false;
		} else {
			downloadTab.css('display', 'inline');
			$(downloadTab.attr('id')+'Dis').css('display', 'none');
		}

	});

	$("#copyCode").click(function(){
		window.clipboardData.setData('Text',document.getElementById("clipEmbedCode").innerHTML);
	});

	$('#emailTab').click(function(){
		return false;
	});
	$(".playlist a").click(function(){
		$('#embedTab').attr('rev', $(this).attr('rev'));
		$('#downloadTab').attr('rev', $(this).attr('rev'));
		$('#downloadTab').attr('href', $(this).attr('rel'));
		if (!$(this).attr('rev').match(reEmbed)) {
			$('#embedTab').css('display', 'none');
			$('#embedTabDis').css('display', 'inline');
		} else {
			$('#embedTab').css('display', 'inline');
			$('#embedTabDis').css('display', 'none');
		}
		if (!$(this).attr('rev').match(reDownload)) {
			$('#downloadTab').css('display', 'none');
			$('#downloadTabDis').css('display', 'inline');
			if (!$(this).attr('rev').match(reLicensed)) {
				try {
				document.getElementById("downloadTabDis").onclick = function (){ light_register_popup();return false;   };
				} catch(e) {};
			}
			else {
				try {
				document.getElementById("downloadTabDis").onclick = function (){ return false; };
				} catch(e) {};
			}
		} else {
			$('#downloadTab').css('display', 'inline');
			$('#downloadTabDis').css('display', 'none');
		}

		$("#currentClipPreviewImg").html($(this).find("img").attr("src").replace("120x90","400x300"));
	});

	// close buttons
	$(".pane .close").click(function() {
		$("#player_actions a").removeClass("active");
		$(this).parent().parent().hide();
		$('#playlist-blocker').hide();
		document.getElementById("clipEmbedCode").innerHTML = "";
	});

}); 

