jQuery.fn.extend({
	labelValue: function()
	{
		jQuery.each(jQuery(this), function(i, item)
		{																	 
			if(jQuery(item).val() == '')  jQuery(item).val(jQuery(item).attr('rel'));
			jQuery(item).focus(function()
			{
				if(jQuery(this).val() == jQuery(item).attr('rel')) jQuery(this).val('');
			});
			jQuery(item).blur(function(){
				if(jQuery(this).val() == '')  jQuery(this).val(jQuery(item).attr('rel'));
			});
		});
		return jQuery(this);
	}
});



 	
 	
 
 
 j = jQuery.noConflict();
j(document).ready(function($)
{
	// PARCEIROS
	//$("a[rel^='prettyPhoto']").prettyPhoto({slideshow:5000, autoplay_slideshow:true});
	
	if($('ul#galleryParceiro li').size() > 8) {
		$('ul#galleryParceiro').carouFredSel({
	    items: 8,
	    height:40,
		direction: "left",
		prev : {   
		        button  : "#prevM",
		        key     : "left"
		},
		next : {
		        button  : "#nextM",
		        key     : "right"
		},
			scroll : {
			items: 2,
			effect: "easeOutBounce",
			duration: 800,                        
			pauseOnHover: true
			}
		});
	}
	
	
	
	$('#header form .input').labelValue();
	$('#comentario .field').labelValue();
	if($('.galery li').size() > 5)
	{
		$('.galery .images').jCarouselLite({
			btnNext: '.galery .next',
			btnPrev: '.galery .prev',
			speed: 800,
			circular: true,
			visible: 5
		});
	}
	if($('#programacao .carrousel li').size() > 3)
	{
		$('#programacao .carrousel').jCarouselLite({
			btnNext: '#programacao  .next',
			btnPrev: '#programacao  .prev',
			speed: 800,
			circular: false,
			visible: 3,
			scroll: 1
		});
	}
	$('#programacao .nav').fadeTo(1500, 1.15).hover(function(){$(this).fadeTo(300, 1);}, function(){$(this).fadeTo(300, 1.15);});
	var painel = $('#programacao .panel');
	var section = $('.section.head, .section.body', painel);
	var body = $('.section.body, .section.rows', painel);
	var run = false;
	var dh = 150;
	var dv = 88;
	var button;
	$('#programacao .nav .top').click(function()
	{
		if(!run && body.position().top < 36)
		{
			run = true;
			body.animate({top: '+='+ dv + 'px'}, 300, function(){run = false;});
		}
	});	
	$('#programacao .nav .bottom').click(function()
	{
		if(!run && (-1)*body.position().top + painel.height() < body.height())
		{
			run = true;
			body.animate({top: '-='+ dv + 'px'}, 300, function(){run = false;});
		}
	});	
	$('#programacao .nav .right').click(function()
	{
		if(!run && (-1)*section.position().left + painel.width() < section.width()-1)
		{
			run = true;
			section.animate({left: '-='+ dh + 'px'}, 300, function(){run = false;});
		}
	});	
	$('#programacao .nav .left').click(function()
	{
		if(!run && section.position().left < 0)
		{
			run = true;
			section.animate({left: '+='+ dh + 'px'}, 300, function(){run = false;});
		}
	});
	$('.pergunta .button').click(function(){
		$('.box-video', $(this).parent().parent()).slideToggle(600); 
	});
	
	$('.conteudo ul li:odd, .comentarios .comentario:odd, #produtos tbody tr:odd').addClass('par');
	$('.conteudo ul li:even, .comentarios .comentario:even, #produtos tbody tr:even').addClass('impar');
	$('.conteiner2', $('.conteudo .hidden').parent()).hide();
	$('.conteiner', $('.conteudo .hidden').parent()).hide();
	$('.conteudo .visibility, .conteudo .abre_aulas_curso').click(function(){
		$('.conteiner',$(this).parent()).slideToggle();
		if($(this).hasClass('hidden'))
		{
			$(this).removeClass('hidden').addClass('visibled');
		}
		else
		{
			$(this).removeClass('visibled').addClass('hidden');
		}
	});
	
	
	
	/*
	$('.box-curso ul li a').tooltip({ 
	    bodyHandler: function() { 
	        return $(this).next().html(); 
	    }, 
	    showURL: false 
	});
	*/
	
	
	
	$('.box-curso .abrir').click(function(){
		$('.conteiner',$(this).parent()).slideToggle();
		if($('.visibility', $(this).parent()).hasClass('hidden'))
		{
			$('.visibility', $(this).parent()).removeClass('hidden').addClass('visibled');
		}
		else
		{
			$('.visibility', $(this).parent()).removeClass('visibled').addClass('hidden');
		}
		return false;
	});
	
	$('.conteudo .abreconteudo').click(function(){
		$('.conteiner',$(this).parent()).slideToggle();
		if($(this).hasClass('hidden'))
		{
			$(this).removeClass('hidden').addClass('visibled');
		}
		else
		{
			$(this).removeClass('visibled').addClass('hidden');
		}
	});
	
	
	$('#curso .bt-info').click(function(){
		$('.box-video').slideToggle(600); 
	});
	$(".dialog").dialog({
		bgiframe: true,
		modal: true,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	$(".dialog-info").dialog({
		bgiframe: true,
		modal: true,
		autoOpen: false,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	//$('.resumo form.conteiner button, .resumo form.conteiner .nota').click(function()
	$('.resumo form.conteiner .nota').click(function()
	{
		if($(this).attr('tagName') == 'BUTTON')
		{	
			form = $(this).parent();
		}
		else
		{
			form = $(this).parent().parent();
			$('#avaliacao').val($(this).val());
		}
		$.getJSON(form.attr('action') + '&' + form.serialize(), function()
		{
			alert(form.serialize());
			$('.dialog-info .notice').html(form.attr('rel'));
			$('.dialog-info').dialog('open');
			if(form.hasClass('clear'))
			{
				$(':input', form).val('');
			}
		});
		return false;
	});
	$('.cep').mask('99.999-999');
	$('.cpf').mask('999.999.999-99');
	$('.data').mask('99/99/9999');
	$('.fone').mask('(99) 9999-9999');

	$('.my-pergunta .resposta').hide();
	$('.my-pergunta .button.r').click(function()
	{
		$('.resposta', $(this).parent()).slideToggle();
	});
	$('.curso .resumo:first .conteiner').show();
	$('.curso .resumo .title').click(function()
	{
		$('.curso .resumo .conteiner:visible').slideUp();
		$(this).next().slideDown();
	});
	
	
	$("#bx-estado").change(function(){
		
	
		$.ajax({
			url: "?metodo=geraCidade",
			dataType: "html",
			type: "post",
			data: "estado="+$("#bx-estado").val(),
			success: function(data){
				
				$("#bx-cidade").html(data);				
			},
			error: function(){ alert("Erro!");}			
			});
	
	});
	
	

	$("#box-recuperar").dialog({
		title: 'Recuperar Senha',
		autoOpen: false,
		height: 150,
		width: 250,
		modal: true,
		buttons: {
			'Recuperar Senha': function() {
				$('form#formRecuperaSenha').submit();
				$(this).dialog('close');
			},
			'Cancelar': function() {
				$(this).dialog('close');
			}
		}
	});
	
	
	
	
	
	/*
	//$(".box-curso ul li a").qtip({
	$(".tooltip").qtip({
		content: $(".tooltip").attr("title"),
		//content: $(this).next().html(),
		   
		   style: { 
			   		name: 'light' // Inherit from preset style
			   },
			   
		   position: {
			   corner: {
				      target: 'topRight',
				      tooltip: 'bottomLeft'
			   }
		   }


		   
		   /*style: { 
		      border: {
		         width: 3,
		         radius: 8,
		         color: '#6699CC'
		      },
		      width: 200
		} */ 
	//});


	
	
	$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
	
		$( "#dialog-message" ).dialog({
			modal: true,
			height: 460,
			width: 830,
			buttons: {
				ACEITAR: function() {
					$( this ).dialog( "close" );
				}
			}
		});
	});
	
	var $j = jQuery.noConflict();
	$j('.conteudo_aba_produto').hide();	
	var opcaoAntiga = 0;	
	abreAbaProduto = function(opcao) {		
		if(opcao != opcaoAntiga){
			$j(".opcao_produto_"+opcaoAntiga).slideToggle();
		}		
		$j(".opcao_produto_"+opcao).slideToggle();		
		opcaoAntiga = opcao;		
		return false;
	};	
	$j('.opcao_produto_3').show();
	
	
	$('.menu_filhos').css('display', 'none');
	$('.abre-sub-menu').click(function() {
		//$('.menu_filhos').slideUp();
		$(this).next().slideToggle();
		//$(this).toggleClass('paracima');
	});
	
	
	
	
	$.fck.config = {path: 'lib/fckeditor/'};
	$('.editor.basic').fck({toolbar: 'MyMain', height: 130});
	
	$('.recuperaEmail').click(function() {
		$('#box-recuperar').dialog('open');
	});
	
	//Player
	
	// VOTA NO PRODUTO
	$("#cadCanal").click(function(){
		var erro= 0;
		var valor = $("#emailCanal").val();			
		if ((valor.length != 0) && ((valor.indexOf("@") < 1) || (valor.indexOf('.') < 7)) || (valor == '')){
		    alert('Informe um E-mail válido !');
			this.focus();
			return false;
		}else{
		$.ajax({
			url:'?metodo=salvaUserCanelNews',
			dataType:'html',
			data:"email="+valor,
			type:'get',
			success:function(data){			
				$('#videoCanal').css('display', 'block');
				$('#cadEmail').css('display', 'none');
				$('#descricaoCanal').css('display', 'none');
			},
			error:function(){
				alert("Error!!");
			}	
		});
		}	
	});
	
	
});
