﻿//Faz os links do flickr abrir em blank
$(document).ready(function(){
	$('#cmbCategoria').change(carregaEquipamentos);
	$('#cmbEquipamentos').change(ativaIdentificacao);
	$('#btnAdicionar').click(adicionarProduto);
	$('#btnRemover').click(removerProduto);
	$('#cmbEstados').change(carregaCidades);
	$('#cmbCidades').change(carregaLojas);
	$('#frmRegistro').submit(validaForm);
	
	function validaForm(){
		var msg = '';
		if($('#txtNome').val() == '') msg = 'Informe seu nome!';
		else if ($('#txtEmail').val() == '') msg = 'Informe seu email!';
		else if ($('#txtEndereco').val() == '') msg = 'Informe seu endereço!';
		else if ($('#txtCidade').val() == '') msg = 'Informe sua cidade!';
		else if ($('#cmbEstado').val() == '') msg = 'Informe seu estado!';
		else if ($('#txtCEP').val() == '') msg = 'Informe seu CEP!';
		else if ($('#txtTelefone').val() == '') msg = 'Informe seu telefone!';
		else if ($('#cmbDiaAniversario').val() == '') msg = 'Informe o dia do seu aniversário!';
		else if ($('#cmbMesAniversario').val() == '') msg = 'Informe o mês do seu aniversário!';
		else if ($('#txtAnoAniversario').val() == '') msg = 'Informe o ano do seu aniversário!';
		else if ($('#minhasCompras option').size() == 0) msg = 'Você não adicionou produtos!';
		else if ($('#listLojas').val() == '') msg = 'Escolha uma loja!';
		
		if(msg != ''){
			alert(msg);
			return false;
		}
		
		$('#minhasCompras option').each(function(){
			$(this).attr('selected', 'selected');
		});
	}
	
	function carregaLojas(){
		var cid = $(this).val();
		$('#listLojas').html('<option value="">Carregando...</option>');
		$.post('ajax/carrega_lojas.php', {cidade:cid}, function(r){
			$('#listLojas').html(r);
		});	
	}
	
	function carregaCidades(){
		var estado = $(this).val();
		$('#cmbCidades').html('<option value="">Carregando...</option>');
		if($('#listLojas option').size() > 1) $('#listLojas').html('<option value="">Selecione...</option>');
		$.post('ajax/carrega_cidades.php', {uf:estado}, function(r){
			$('#cmbCidades').html(r);
		});
	}
	
	function removerProduto(){
		$('#minhasCompras option:selected').remove();
		if($('#minhasCompras option').size() == 0) $(this).fadeOut();
	}
	
	function adicionarProduto(){
		var categoria = $('#cmbCategoria').val();
		var produto = $('#cmbEquipamentos').val();
		var identificacao = $('#txtIdentificacao').val();
		
		if(!categoria || !produto || !identificacao){
			alert('Verifique a categoria, equipamento e a identificação');
			return false;
		}
		
		var nomeCategoria = $('#cmbCategoria').find('option[value="'+categoria+'"]').html();
		var nomeProduto = $('#cmbEquipamentos').find('option[value="'+produto+'"]').html();
		var valorOption = produto+'-'+identificacao;
		var optionMinhasCompras = '<option value="'+valorOption+'">'+identificacao+" - "+nomeCategoria+" - "+nomeProduto+'</option>';
		
		if($('#minhasCompras').find('option[value="'+valorOption+'"]').size()){
			alert('Produto já adicionado!');
			return false;	
		}
		
		$('#minhasCompras').append(optionMinhasCompras);
		
		$('#btnRemover').fadeIn();
	}
	
	function ativaIdentificacao(){
		if($(this).val() != ''){
			$('#txtIdentificacao').removeAttr('disabled');
			$('#btnAdicionar').fadeIn();
		}else{
			$('#txtIdentificacao').attr('disabled', 'disabled');
			$('#btnAdicionar').fadeOut();
		}
	}
	
	function carregaEquipamentos(){
		var categoria = $(this).val();
		$('#cmbEquipamentos').html('<option value="">Carregando...</option>');
		$.post('ajax/carrega_equipamentos.php', {cat:categoria}, function(r){
			$('#cmbEquipamentos').html(r);
		});
	}
	
	$('a[href^="http://www.flickr.com/"]').attr("target", "_blank");
});

// Slideshow Image Home
$(document).ready(function(){
	$('#slideshow-image').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '269px'
	});
});

// Slideshow Text Home
$(document).ready(function(){
	$('#slideshow-text').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '115px'
	});
});

// Slideshow Image Parceiros
$(document).ready(function(){
	//$('#parceiros').innerfade({
	//	speed: 700,
	//	timeout: 2000,
	//	type: 'sequence',
	//	containerheight: '160px'
	//});
});

//Carousel
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();
    });
};

jQuery(document).ready(function() {
    jQuery('#destaque-list').jcarousel({
		auto: 5,
        vertical: true,
        scroll: 1,
        initCallback: mycarousel_initCallback
    });
});

// Menu Top
$(function() {
	$('#navigation').lavaLamp({
			fx: 'easeOutCirc',
			//fx: 'easeInOut'+easing,
			speed: 600,
			autoReturn: false
	});
});
	
var query = new Object();
	window.location.search.replace(

new RegExp( "([^?=&]+)(=([^&]*))?", 'g' ),
	function( $0, $1, $2, $3 ){
		query[ $1 ] = $3;
	}
);

easing = query['e'] || 'Expo';
	
function loadEasing(e) {
	location.href = location.pathname+'?e='+e;
}

function setEasing(e) {
	loadLamps(e);
}

// Redes Sociais


//Pirobox
$(document).ready(function() {
	$().piroBox({
			my_speed: 600, //animation speed
			bg_alpha: 0.5, //background opacity
			radius: 4, //caption rounded corner
			scrollImage : true, // true == image follows the page, false == image remains in the same open position
			pirobox_next : 'piro_next_out', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
			pirobox_prev : 'piro_prev_out',// Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
			close_all : '.piro_close, .piro_overlay',// add class .piro_overlay(with comma)if you want overlay click close piroBox
			slideShow : 'true', // just delete slideshow between '' if you don't want it.
			slideSpeed : 4 //slideshow duration in seconds(3 to 6 Recommended)
	});
});

//Anything Slider 
function formatText(index, panel) {
  return index + "";
    }
    
	$(function () {
        
    	$('.anythingSlider').anythingSlider({
                easing: "swing",        // Anything other than "linear" or "swing" requires the easing plugin
                autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
                delay: 10000,                   // How long between slide transitions in AutoPlay mode
                startStopped: false,            // If autoPlay is on, this can force it to start stopped
                animationTime: 600,             // How long the slide transition takes
                hashTags: true,                 // Should links change the hashtag in the URL?
                buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
        		startText: "",  	           	// Start text
		        stopText: "", 	    	        // Stop text
		        navigationFormatter: null // Details at the top of the file on this use (advanced use)
	});
            
		$("#slide-jump").click(function(){
			$('.anythingSlider').anythingSlider(6);
       });
            
});

//Featured Content
$(document).ready(function(){
	$("#featured > ul").tabs({
		fx:{opacity: "toggle"}}).tabs("rotate", 7000, true);
});


//Ronded Corners
$(function(){
	$('h3.page-line, h3.page-item, .page-details, .linha-item, #tooltip, h3.multisports, #novidades ul li, .ronded, ul#destaque-list li').corner();
});


//Close Bubbles
$(function(){
	$("#close-bubble").click(function(){
		$('.page-details').fadeOut(300);
	});
});

//Vai pro 'a' quando clicka na 'div'
$(document).ready(function(){						   
	$(".produtos-outdoor, .produtos-liners, .produtos-multisport, .produtos-walking, .produtos-moto, .produtos-industrial, .produtos-inverno").click(function(){
    	window.location=$(this).find("a").attr("href");return false;
	});
});


//Hover Características do Produto
$(document).ready(function(){	
	$('#caracteristicas span#lupa').hide();

	$('#caracteristicas a.pirobox').hover(
	  function () {
		$('#caracteristicas span#lupa').fadeIn(300);
	  },
	  function () {
		$('#caracteristicas span#lupa').hide();
	  });
});


//Icons to Share
$(function(){
	
	$(".icons-to-share").hide();
	
	$("span#share-this").toggle(
    	function () {
        	$('.icons-to-share').fadeIn(300);
      	},
      	function () {
        	$('.icons-to-share').fadeOut(300);
      	});
//	$('.icons-to-share').hide();	   
		   
//	$("span#share-this").mouseover(function(){
//		$('.icons-to-share').fadeIn(300);
//	});
//	$(".icons-to-share").mouseout(function(){
//		$('.icons-to-share').fadeOut(300);
//	});
});


//Muda o produto, quando clica na cor das imagens
function switch_product_img(divName, totalImgs) {
	for (var i=1; i<=totalImgs; i++) {
		var showDivName = 'preview_' + i;
		var showObj = document.getElementById(showDivName);
			if (showDivName == divName)
				showObj.style.display = 'block';
			else
				showObj.style.display = 'none';
			}
}

//Star Rating
function Vote(pts,obj,ip) {
 jphp("POST", "votar.php", "pts="+pts+"&obj="+obj+"&ip="+ip,"ShowRating");
}

function ShowRating(html) {
 var ret = html.split("|");
 document.getElementById(ret[0]).className = 'rating '+ret[1];
}
