$(document).ready(function() {
   // put all your jQuery goodness in here.
$("#search").focus(function(){
		// If the value is equal to "Search..."
		if($(this).val() == "Search...") {
			// remove all the text and the class of .empty
			$(this).val("").removeClass("empty");;
		}
	});
$(".seletor[feed='youtube']").css("background-color","#eeeeee");
$(".seletor[feed='youtubepref']").css("background-color","#dddddd");
$(".seletor[feed='youtubefeed']").css("background-color","#FFddee");
 });

function advertise_centro()
{
//$("#playlistad").html("");
//$("<iframe/>").src("http://www.vejatv.com/new/ad.php").appendTo("#playlistad");
$("#playlistad").html('<iframe id="myframe" name="myframe" style="height:80px;width:570px" class="autoHeight" scrolling="auto" frameborder="0" src="http://vejatv.com/new/ad.php"></iframe>');
	$('#playlistad').animate({ height: '1'
  }, 300, function() {
    // Animation complete.
  });
	$('#playlistad').animate({ height: '80'
  }, 1000, function() {
    // Animation complete.
  });


}
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};



	$(function() {
$(".meu-button").hover(
				function(){ $(this).addClass('ui-state-hover'); }, 
				function(){ $(this).removeClass('ui-state-hover'); }
			);
$(".meu-button2").hover(
				function(){ $(this).addClass('ui-state-hover'); }, 
				function(){ $(this).removeClass('ui-state-hover'); }
			);

$(".box2").hover(
				function(){ $(this).addClass('ui-state-hover'); }, 
				function(){ $(this).removeClass('ui-state-hover'); }
			);


$(".tumbs1").live({
                mouseover: function() {
				$(this).find(".preview").addClass('fundopreview');
				$(this).find(".later").addClass('fundolater');
                           },
                mouseout: function() {
				$(this).find(".preview").removeClass('fundopreview');
				$(this).find(".later").removeClass('fundolater');
                           }
                });






$(".tumbs1 .preview").live({
                click: function() {
                        var video=$(this).parent().attr('rel');
                        var videot=$(this).parent().attr('rel2');
                        $("#centroi h3").html("Now previewing "+"video selected <img src='http://www.vejatv.com/magick.php/tumb/"+videot+".jpg?resize(120x90)' alt='preview' width=30/>");
                        $("#meuembed").css("z-index","99");
                        $("#meuembed").load("new/centralv.php?id="+video);
			var new_position = $('#principal').offset();
    			window.scrollTo(new_position.left,new_position.top);
                        return false;
                	}
                });


$(".tumbs1 .later").live({
                click: function() {
                        var new_position = $('#principal').offset();
                        window.scrollTo(new_position.left,new_position.top);
 
  			var video=$(this).parent().attr('rel2');
  			var playlisttemp=$.cookie('playlisttemp');
  			var achou = playlisttemp.indexOf(video);
        			if(Number(achou) <0 )
        			{
                			$.cookie('playlisttemp', $.cookie('playlisttemp')+video+";");
                			montaplaylist();
        			}
        			else
        			{
            			var answer = confirm("This video is already in your playlist\nDo you want to put it there anyway ?")
            			if (answer){
                			$.cookie('playlisttemp', $.cookie('playlisttemp')+video+";");
                			montaplaylist();
                			}
        			}

                        return false;
                	}
                });





    jQuery('#mycarousel').jcarousel({
        auto: 5,
        scroll: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
$('.jcarousel-container').append('O Vejatv oferece a voce uma selecao de canais de parceiros e afiliados');

montaplaylist();
$('div.tumbs1').draggable({
			helper: 'clone',
			revert: true,
			start: function() {
			$("#dragspace").show(1000);
			$("#recebeplaylist2").show(1000);
			
			},
			drag: function() {
			},
			stop: function() {
			$("#dragspace").hide();
			$("#recebeplaylist2").hide(1000);
			}});




$('#recebeplaylist').sortable({
			placeholder: "ui-state-highlight",
			update: function(ev,ui) {
			var tempi="";
			$('#recebeplaylist li').each(function(i) {
                        	valor=$(this).attr('rel');
                        	if(valor>0)
                        	{
                        		tempi=tempi+valor+";";
                        	}
			});
			$.cookie('playlisttemp', tempi);
			alert("Playlist re-ordenado");
			}
		});



$( "#recebeplaylist" ).disableSelection();


function handleDropEvent( event, ui ) {
  var draggable = ui.draggable;
  var video=draggable.attr('rel');
$("#meuembed").load("new/centralv.php?id="+video);
}


function handleDropEvent2( event, ui ) {
  var draggable = ui.draggable;
  var video=draggable.attr('rel2');
  var playlisttemp=$.cookie('playlisttemp');
  var achou = playlisttemp.indexOf(video);
	if(Number(achou) <0 )
	{
		$.cookie('playlisttemp', $.cookie('playlisttemp')+video+";");
		montaplaylist();
	}
	else
	{
	    var answer = confirm("This video is already in your playlist\nDo you want to put it there anyway ?")
	    if (answer){
		$.cookie('playlisttemp', $.cookie('playlisttemp')+video+";");
		montaplaylist();

		}


	}
}

function montaplaylist()
{
if($.cookie('playlisttemp')==null)
{
$.cookie('playlisttemp',"");
return true
}
var playlisttemp=$.cookie('playlisttemp');
var exploded = playlisttemp.split(';');
var n=0;
$("#recebeplaylist").html("");
$("#recebeplaylist").append("<ul'>");
$(exploded).each(function(index) 
{
var xx=exploded[index];
if(xx!="undefined" &&xx!="")
{
	n++;
	$("#recebeplaylist").append("<li class='ui-state-default ui-corner-all' rel='"+exploded[index]+"'><img src='http://www.vejatv.com/magick.php/tumb/"+exploded[index]+".jpg?resize(120x90)' width=50 height=50><a href='#'><span class='ui-icon ui-icon-close'></span></a></li>");
}
});
$("#recebeplaylist").append("</ul>");
	if(n>0)
	{
	$("#recebeplaylist").append("<ul class='acao'> <li><a href='#' id='deleteplaylist' >Delete</a></li> <li><a href='#' id='playplaylist' >Play</a></li> <li><a href='#' id='saveplaylist' >Save</a></li></ul>");
}
$("#recebeplaylist").append("<div style='clear:both'></div>");
}

$("#recebeplaylist span").live({
        mouseenter:
           function()
           {
		$(this).addClass('ui-state-default');

           },
        mouseleave:
           function()
           {
		 $(this).removeClass('ui-state-default');
           }
       }
    );


$('#deleteplaylist').live('click', function() {
    var answer = confirm("Confirma exclusao deste playlist ?")
    if (answer){
	$.cookie('playlisttemp',"");;
	$("#recebeplaylist").html("");
    }
    return false;  
});


//$('.tumbs1').live('click', function() {
    //$("#repos").show();
    //var video=$(this).attr('rel');
    //$("#meuembed").load("new/centralv.php?id="+video);
    //return false;  
//});

$('.searchmais').live('click', function() {
    //$("#repos").show();
    var rel=$(this).attr('rel');
    var searcha=$(this).attr('rel2');
    $(this).html("Searching...");
    $(this).load("new/searchmais.php",{pag:rel,search:searcha});
    return false;  
});

              $( "#accordion" ).show().accordion({
			animated: true,
			fillSpace: true
              });

              $("#xtra").show().accordion({
		active:false,
		autoHeight: false,
		hideSpeed: 800,
		header: 'h4.head',
		collapsible: true
              });

              $("#xtra1").show().accordion({
		active:false,
		autoHeight: false,
		hideSpeed: 800,
		header: 'h4.head',
		collapsible: true
              });

              $("#xtra2").show().accordion({
		active:false,
		autoHeight: false,
		hideSpeed: 800,
		header: 'h4.head',
		collapsible: true
              });


              $("#xtra3").show().accordion({
		active:false,
		autoHeight: false,
		hideSpeed: 800,
		header: 'h4.head',
		collapsible: true
              });



$("#newsradio img").click( function(){
$("#centroi h3").html("Now playing live radio").show(1000);
                pos = $(this).attr("id");
                $("#meuembed").load("new/centralradio.php",{id:pos});
                                //$("#detach_radio").show();

                                //$('#detach_radio').html("<img href='"+pos+"' src='detach_hand.png'>");
          });

$('#playplaylist').live('click', function() {
	var tempi=$.cookie('playlisttemp');
    $("#meuembed").load("new/centralplaylist.php?id="+tempi);
    return false;  
});

$('.ad33').live('click', function() {
	var tempi=$.cookie('playlisttemp');
	var tempi=351;
	$("#centroi h3").html("Playing Stop Shop");
    $("#meuembed").load("new/centralad.php?id="+tempi);
    return false;  
});

$('#saveplaylist').live('click', function() {
	$("#salvaplaylist").show('fast');
	var tempi=$.cookie('playlisttemp');
		$("#salvaplaylist").load("formsalvaplaylist.php?pl="+tempi);
    return false;  
});


$('#sclose').live('click', function() {
		$("#salvaplaylist").hide(1000);
    return false;  
});


$('#dragmehere').droppable( {
    drop: handleDropEvent,
    hoverClass: 'hovered'
  } );

$('#recebeplaylist2').droppable( {
    drop: handleDropEvent2,
    hoverClass: 'hovered'
  } );

		$( "div#recebeplaylist li span").live('click' ,function() {
			var apagar=$(this).parent().parent().attr('rel');
			var tempi="";
                        $('#recebeplaylist li').each(function(i) {
				if(apagar!=$(this).attr('rel'))
				{
						valor=$(this).attr('rel');
						if(valor>0) 
						{
							tempi=tempi+valor+";";
						}
				}
                        });
			$.cookie('playlisttemp', tempi);
			$(this).parent().parent().hide(1000);
			return false; 
		});


		//$( "input:submit, a, button", ".demo" ).button();
		$( "a", ".demo" ).click(function() { return false; });
		$( ".seletor " ).click(function() { 
			var currentref = $(this).attr('ref');
			var typeseletor = $(this).attr('feed');
			if(typeseletor=="youtube")
			{
				var texto=$(this).text();
				$("#centroi h3").html("Now playing "+texto);
				$("#meuembed").css("z-index","99");
				$("#meuembed").load("new/centralseletory.php?id="+currentref);
			}
			else if(typeseletor=="youtubepref")
			{
				var texto=$(this).text();
				$("#centroi h3").html("Now playing pref "+currentref);
				$("#meuembed").css("z-index","99");
				$("#meuembed").load("new/centralseletoryp.php?id="+currentref);
			}
			else if(typeseletor=="youtubefeed")
			{
				var texto=$(this).text();
				$("#centroi h3").html("Now playing youtube feed ");
				$("#meuembed").css("z-index","99");
				$("#meuembed").load("new/centralseletoryf.php?id="+currentref);
			}
			else
			{
				var texto=$(this).html();
				$("#centroi h3").html("<img src='images/logovejatvp.jpg' width='32' border='0'> Now playing "+texto);
				$("#meuembed").css("z-index","99");
				$("#meuembed").load("new/centralseletor.php?id="+currentref);
			}
			return false; });


	//$("div.j1 img").mouseover(function(){
    	//	$(this).removeClass().addClass("sidenavOver");
    	//}).mouseout(function(){
	
    //	$(this).removeClass().addClass("sidenavOff");		
   // });
$( "ul.thumbj1 li" ).click(function() {
                        var currentref = $(this).attr('rel');
                        $("#expande").load("novo/adv.php?ad="+currentref);
			$("#expande").show("fast");
                        return false; });

$( "#idx" ).click(function() {
			$(this).parent().hide("slow");
			$("#idxo").show("slow");
                        return false; });
$( "#idxo" ).click(function() {
			$("#bidad").show("slow");
			$("#idxo").hide("slow");
                        return false; });

$("#idx").hover(
	function(){
		$(this).css("border","1px solid #FF0000");
	},
	function(){
		$(this).css("border","none");
	}	
);

$("ul.thumbj1 li").hover(function() {
	$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
	$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
		.animate({
			marginTop: '5px', /* The next 4 lines will vertically align this image */ 
			marginLeft: '5px',
			width: '80px', /* Set new width */
			height: '80px', /* Set new width */
			padding: '8px'
		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

	} , function() {
	$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
	$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
		.animate({
			marginTop: '0', /* Set alignment back to default */
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '60px', /* Set width back to default */
			height: '60px', /* Set width back to default */
			padding: '5px'
		}, 400);
});


	});
$("#detach").live({click: function() {
        alert("Voce esta abrindo uma nova janela em seu browser\nAgora voce pode minimizar esta janela e continuar tocando o player enquanto trabalha");
    var recipe =  window.open('','RecipeWindow','width=450,height=600');    var html = '<title>Detached video</title><body><div id="myprintrecipe">' + $('<div />').append($('#meuembed').clone()).html() + '</div>';
    recipe.document.open();
    recipe.document.write(html);
    recipe.document.close();

    return false;
}
    });

