//MUESTRA Y OCULTA INGRESO MAIL FEED BURNER
$(document).ready(function(){
    //valor inicial campo email
    $('#mailFeedBurner').attr("value", "Tu email");
    
    //borrando valor
    $('#mailFeedBurner').focus(function(){
        if ($('#mailFeedBurner')[0].value == "Tu email") {
            $('#mailFeedBurner').attr("value", "");
        }
    });
    
    //reinicia valores iniciales
    $('#mailFeedBurner').blur(function(){
        if ($('#mailFeedBurner')[0].value == "") {
            $('#mailFeedBurner').attr("value", "Tu email");
        }
    });
	
	
	window.fbAsyncInit = function() {
		FB.init({
			appId      : '121400484630418', // App ID	      
			status     : true, // check login status
			cookie     : true, // enable cookies to allow the server to access the session
			oauth      : true, // enable OAuth 2.0
			xfbml      : true  // parse XFBML
	    });
    
	    $('.btn_facebook').click(function(){
	        FB.login(function(respuestaLogin){
	            if (respuestaLogin.authResponse) {
	                
	                    $.ajax({
	                        url: ruta + '/libs/session.php',
	                        data: 'ajax=false',
	                        success: function(msg){
	                        
	                            window.location.reload();
	                            
	                        }
	                    });
	                
	            }
	        }, {
	            scope: 'email, publish_stream'
	        });
	        
	    });
	    
	
    
	    $('#pop_fb2').click(function(){
	    
			var titulo = $('#fb_titulo').val();
			var descripcion = $('#fb_descripcion').val();
			var link = $('#fb_link').val();
		
		
	        FB.ui({
	            method: 'stream.publish',
	            message: '',
	            attachment: {
	                name: 'Sedal.cl',
	                caption: titulo,
	                description: (descripcion),
	                href: link
	            },
	            action_links: [{
	                text: 'Sedal',
	                href: link
	            }],
	            user_message_prompt: 'Comparte con tus amigos en Facebook'
	        }, function(response){
	            if (response && response.post_id) {
	                //alert('Post was published.');
	            }
	            else {
	                //alert('Post was not published.');
	            }
	        });
	        return false;
	    });
	
	};
	// Load the SDK Asynchronously
	(function(d){
		var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
		js = d.createElement('script'); js.id = id; js.async = true;
		js.src = "//connect.facebook.net/en_US/all.js";
		d.getElementsByTagName('head')[0].appendChild(js);
	}(document));
    
    
    
    $("a#pop_fb").fancybox({
        'padding': 1,
        'frameHeight': 365,
        'frameWidth': 710,
        'easingChange': true,
        //editando alto frames (arregla falla en ie7 y 8)
        'callbackOnShow': altoIframe,
        'hideOnContentClick': false
    });
    
    $("a#pop_tw").fancybox({
        'padding': 1,
        'frameHeight': 440,
        'frameWidth': 650,
        'easingChange': true,
        //editando alto frames (arregla falla en ie7 y 8)
        'callbackOnShow': altoIframe,
        'hideOnContentClick': false
    });
    
 
    
    
    $('#suscribirse').click(function(){
    
        var email = $('.inputnews').val();
        
	
        $('.inputnews').val('Agregando Correo...');
        
        // Prepare query string and send AJAX request
        $.ajax({
            url: ruta + '/libs/mailchimp.php',
            data: 'ajax=true&email=' + escape(email),
            success: function(msg){
                $('.inputnews').val(msg);
            }
        });
        
        return false;
        
    });
    
    //despliega/oculta caja
    $('.sigueSedal').click(function(){
        $("#feedBurnerBox").slideToggle();
        $('.feedMain p').removeClass("texoError");
        $('.feedMain p').html('Suscr\xEDbete y recibe por email las \xFAltimas novedades y promociones de Sedal Chile.');
    });
    $('.btnCerrar').click(function(){
        $("#feedBurnerBox").fadeOut();
        $('.feedMain p').removeClass("texoError");
        $('.feedMain p').html('Suscr\xEDbete y recibe por email las \xFAltimas novedades y promociones de Sedal Chile.');
        $('#input-feedburner').val('Tu email');
    });
});

//VALIDA FEEDBURNER
$(document).ready(function(){
    //$('#input-feedburner').attr('autocomplete', 'off');
    $('#input-feedburner').focus(function(){
        var valorInicialMail = $('#input-feedburner').val();
        if (valorInicialMail == "Tu email") {
            $('#input-feedburner').val('');
        }
    });
    $('#feedburner').attr('name', 'feedburner');
    $('#feedburner').attr('target', '_blank');
    $('.submitFeedBurner').click(function(){
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('input[name=email]').val())) {
            document.forms[0].submit();
            setTimeout(function(){
                $('#feedBurnerBox').fadeOut();
                $('#input-feedburner').val('Tu email');
            }, 1000);
        }
        else {
            $('.feedMain p').addClass("texoError");
            $('.feedMain p').html('Ingrese una direcci\xF3n de correo v\xE1lida.');
        }
    });
    /*$('#feedBurnerBox').mouseenter(function(){
     $('#feedBurnerBox').show();
     }).mouseleave(function(){
     $('#feedBurnerBox').fadeOut();
     });*/
});

//VALIDA BUSQUEDA
$(document).ready(function(){
    $('#formBusqueda').attr('name', 'searchForm');
    $('#s').focus(function(){
        var busqueda = document.getElementById('s').value;
        if (busqueda == "Ingresa tu b\xFAsqueda") {
            $('#s').attr("value", "")
            $('.btnBuscar').attr("href", "javascript:;");
        }
    });
    //accion boton
    $('#searchsubmit').click(function(){
        var busqueda = document.getElementById('s').value;
        if (busqueda == "" || busqueda == "Ingresa tu b\xFAsqueda") {
            $('#s').attr("value", "Ingresa tu b\xFAsqueda")
            $('.btnBuscar').attr("href", "javascript:;");
        }
        else {
            document.forms[1].submit();
        }
    });
});

//fix ie6 para enlace del logo
$(document).ready(function(){
    var enlaceHome = $("#menu .logo")[0].href;
    $("#menu h1").click(function(){
        window.location = enlaceHome;
    });
});

//EFECTO HOVER SOBRE MENU
$(document).ready(function(){
    $('.liBlog a').blend();
    $('.liProductos a').blend();
    $('.liPromociones a').blend();
    $('.liConsejos a').blend();
    $('.liHome a').blend();
});

$(document).ready(function(){
    var over = new Array();
    var over = $('.jsblend');
    jQuery.each(over, function(i){
        over[i].style.backgroundPosition = "50% -40px";
    });
});



