﻿var masterPageValue = "#ctl00_";
var masterValue = "#ctl00_";
var basketId = "#ctl00_PanelBasket"

$(document).ready(initControls);



function showLogin() {

    if ($("#login").css("height") == "51px") {
        $("#login").animate({
            height: "0px",
            marginTop: "0px"
        }); 
    }
    else { 
        $("#login").animate({
            height: "51px",
            marginTop: "10px"
        });  
    }

}

function showRegistro() {
    if ($("#register").css("height") == "51px") {
        $("#register").animate({
            height: "0px",
            marginTop: "0px"
        });
    }
    else {
        $("#register").animate({
            height: "51px",
            marginTop: "10px"
        });
    }

}

function clearText(inputName)
{
    $(masterPageValue + inputName).value = "";
    $(masterPageValue + inputName).focus();
}


/***
 *
 *  SEARCH FUNCTIONS
 *
 ***/

function initControls()
{
    $("#ctl00_tbxSearch").blur(setSearchInput);
    $("#ctl00_tbxSearch").focus(focusSearchInput);
    moveit();
    $(basketId).css("position", "absolute");
    $(basketId).css("left", ($(window).width() / 2 + 278 + "px"));
    $(masterPageValue + "PanelBasket").css("position", "absolute");
    $(masterPageValue + "marcianoBox").css({ opacity: 0.7 });
    setTimeout('$(masterPageValue + "marcianoBox").animate({height:"0px"})', 5000);
    $(masterPageValue + "marcianoBox").click(function() { $(masterPageValue + "marcianoBox").animate({ height: "0px" }) });
}


function setSearchInput() 
{
    var id = masterValue + "tbxSearch";
    if (jQuery.trim($(id).attr("value")) == "")
    {
        $(id).attr("value", "Escribe aquí tu búsqueda");
        // Hide advanced options
        $("#SearchOptions").animate({ height: "0px" });
    }
}

function focusSearchInput() 
{
    var id = masterValue + "tbxSearch";
    if (jQuery.trim($(id).attr("value")) == "Escribe aquí tu búsqueda")
    {
        $(id).attr("value", "");
    }
    // Show advanced options
    $("#SearchOptions").animate({ height: "40px" });
} 


/***
*
*  MOVE BASKET
*
***/


var interval = 0;
function moveit() {
    clearInterval(interval);
    interval = setInterval(_moveit, 200);
}

function _moveit() {
    $(basketId).stop();
    $(basketId).css("left", ($(document).width() / 2 + 285 + "px"));
    var posX = $(window).scrollTop() < 180 ? 180 : $(window).scrollTop();
    setTimeout('$(basketId).animate({ top: ' + posX + ' }, {queue:false, duration:500, easing:"quadEaseOut"})', 500);
    clearInterval(interval);
}

$(window).scroll(moveit);
$(window).resize(moveit);
