$(document).ready(function() 
{
	
	
	
	var film = getFlashMovie('player2');

	if(film != undefined)
	{
		if(film.PercentLoaded() != 100)
		{
			$("#writer_site").everyTime(100, function () 
			{
				if(film.PercentLoaded() == 100)
				{
					$("#writer_site").stopTime();
					//start_movie();
				}
			});
		}
		else
		{
			//start_movie();
		}
	}
	
	
	
	
	//add_content_item();			
				
	
	tabele();
	delCampaign();
	alignMiddle('tablesorter', '.');
	
	$(".tablesorter tr").mouseover(function() {$(this).addClass("trOver");}).mouseout(function() {$(this).removeClass("trOver");});
	$('.tablesorter tr:even').addClass('trAlt');
	
	adsLink();
});

function getFlashMovie(movieName) 
{
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

function tabele()
{
	$('#campaignlist').tablesorter();
	$('#adlist').tablesorter();
}

function load_movie(film, stream)
{
	film.decryptAndLoad(stream, 1);
}


//flash document.write
function no_flash(version)
{
	var alternateContent = '<div style="width:720px; height:305px; background:#111; margin: 0px auto; text-align:center; padding-top:200px; border:none;"><h2 style="color: #ccc;">Pentru a viziona filmul, aveti nevoie de cel putin Flash Player v'+version+'</h2><a href="http://www.adobe.com/go/EN_US-H-GET-FLASH" target="_blank"><img src="img/get_adobe_flash_player.jpg" style="border:none;"/></a></div>';
	document.write(alternateContent);
}



/* FUNCTII */

function sortable_init()
{
	$(".play-ul").sortable(
	{
		stop: function () 
		{
			
        	//ulcolors();
        	
        	//stabilim ordinea dupa sortare si salvam
        	var order = "";
        	var count = 0;
        	
        	$(".playlist_order").each(function () {
        		if(count == 0)
        			order = $(this).val();
        		else
        			order += ","+$(this).val();
        		
        		count = 1;	
        	});
        	
        	var user = $("#vod_user").val();
        	
        	
        	$.ajax(
	 		 {
				   type: "GET",
				   url: "http://www.mediadirect.ro/contentdelivery/index/movesong/songs/"+order+"/user/"+user,
				   success: function (msg) { ulcolors(); }
	 		});
	 		//end stabilire ordine
	 		
	 		
	 		var nextsong = $(".nowplaying").next().children(".play-right").children(".playlistmel").attr("href");
	 		$("#nextsong").val(nextsong);
	 		
		}
		,
		opacity: 0.7,
		axis: 'y',
		containment: $("#playlist_content")
	});
}

function alignMiddle(id_or_class, diez_or_dot)
{
	if($(diez_or_dot+id_or_class).size() > 0)
	{
		var width = ($(document).width()-$(diez_or_dot+id_or_class).css("width").split("px")[0])/2;
		$(diez_or_dot+id_or_class).css("margin-left", width+"px");
	}
}

function delCampaign()
{	
	$('.deleteCampaignBtn').click(function (event) 
	{
		
		var deleteCampaign = confirm('Esti sigur ca vrei sa stergi campania ?');
		if (deleteCampaign)
		{
			var deleteAds = confirm('Vrei sa stergi si anunturile din aceasta campanie ?');
			if (deleteAds)
			{
				$(this).attr('href', $(this).attr('href') + "/delete/ads");
			}
			
		}
		else 
			return false;

	});
}

function resize(w,h)
{
	var vid = getFlashMovie('player2');
	vid.width = w;
	vid.height = h;
	
	if($('#player-container').css('width') < w)// < w && $('#player-container').css('height') < h)
	{
		$('#player-container').css('width', w);
	}
	
	$('#player-container').css('height', h);
	

	$('#player').css('height', h); //.css('margin-left', parseInt((parseFloat($('#player-container').css('width'))-w)/2));
	
	//getFlashMovie('player2').css('width', w).css('height', h);   .css('width', w)
	
	return true;
}

function adsLink()
{

	$('.linkAds').live('click', function(event){
		event.preventDefault();
		$(this).attr('class','linkAdsA');
		var id = $(this).attr('id');
		$('#ads_'+id).html('<center><img src="images/loading10.gif" /></center>');
		$('#ads_'+id).slideDown('fast',function(){
			$.ajax({ 
				url: "default/campaigns/get-ads/campaign/"+id,
				success: function(msg){
					$('#ads_'+id).slideUp('fast',function() {
						$('#ads_'+id).html(msg);
						$('#ads_'+id).slideDown('fast');
					});
					
		      	}
			});
		});
		
		
	});
	
	$('.linkAdsA').live('click', function(event){
		event.preventDefault();
		$(this).attr('class','linkAds');
		var id = $(this).attr('id');
		$('#ads_'+id).slideUp('slow');
	});
}
