$(document).ready(
	function()
	{
		// Controls Drag + Drop
		$('#columns td').Sortable(
			{
				accept: 'portlet',
				helperclass: 'sort_placeholder',
				handle: 'div.portlet_topper',
				opacity: 0.5,
				tolerance: 'pointer',
				update: function(e,ui) { alert("PASSOU"); },
				onStop: verificaPosicoes  
			}
		);
		
		$("#top1 #barraProgresso, #top2 #barraProgresso, #top3 #barraProgresso, #top4 #barraProgresso, #top5 #barraProgresso, #top6 #barraProgresso, #top7 #barraProgresso, #top8 #barraProgresso, #top9 #barraProgresso, #top10 #barraProgresso").Draggable(
			{
				zIndex: 	1000,
				ghosting:	true,
				opacity: 	0.7,
				onStart: teste,
				onChange: teste,
				onDrag: movendo,
				onStop: terminou,
				axis: 'horizontally'
			}
		);

	$("#top1 #btnPlayPause, #top2 #btnPlayPause, #top3 #btnPlayPause, #top4 #btnPlayPause, #top5 #btnPlayPause, #top6 #btnPlayPause, #top7 #btnPlayPause, #top8 #btnPlayPause, #top9 #btnPlayPause, #top10 #btnPlayPause,").click( function (){
		playPause($(this));
	});
		
	$("#top1, #top2, #top3, #top4, #top5, #top6, #top7, #top8, #top9, #top10,").click( function (){
		if($(this).find("div:first").css("display")=='none'){
			$(this).find("div:first").css("display" , "block");
			$(this).css("background","#0C0C0C");
		}
	});

	$("#busca_btn").click( function (){
		$("#frmBusca").submit();
	});

	}
);

var col1="";
var col2="";
var col3="";

function verificaPosicoes(){
	col1=col2=col3="";
	$('.portlet').each(function(){
		$(this).each(function(){
			if( $(this).parent().attr("id") == "coluna1" )
				col1+= $(this).attr("id") +",";
			else if($(this).parent().attr("id") == "coluna2" )
				col2+= $(this).attr("id") +",";
			else if($(this).parent().attr("id") == "coluna3")
				col3+= $(this).attr("id")+",";
		});
	});
	var lista = col1 + "/" + col2 + "/" + col3;
	createCookie("configCombos", lista, 0);
}

function efetuaVotacao(){
	var opcao="";
	$(".optEnquetes").each(function(){
		if($(this).attr("checked"))
			opcao=$(this).attr("value");
	});
	
	if(opcao!=""){
		$("#box_enquetes_alternativas").load("computaVoto.aspx?opcao=" + opcao+"&idPromocao="+ $("#box_enquetes").attr("idPromocao") + "&rnd="+ Math.random());	
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function carregaResultado(){
	$("#box_enquetes_alternativas").load("carregaResultado.aspx?idPromocao=" + $("#box_enquetes").attr("idPromocao")+"&rnd="+ Math.random());	
}

function mudouPosicao(){
	alert("passou");
}

function trocaBotao(valor, obj){
	obj.css("background-image", "url('../images"+ valor +".gif')" );
	obj.css("background-repeat", "no-repeat" );
	//obj.html("<img src=\"../images/playTopMix/"+ valor +".gif\">" );
}

function movendo(){
	//barraProgressoLoad.css("width","0px");
}

function terminou(){
	movePosicao(barraProgresso.css("left"));
}


function teste(){
	$("#top1").css("display","block");
}

function printPlayer (strObject) {
	document.write(strObject);
}
