/**
 * This file is part of the sinersis proyect.
 * (c) 2010 RADMAS S.L. Rad(+) Technologies
 * (c) 2010 SINERSIS ESTRATEGIAS DE DISTRIBUCIÓN, S.A.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package     : sinersis
 * @author      : Daniel Gonzalez <daniel.gonzalez@radmas.com>
 */

$(document).ready(function() {

    /* shadowbox */
    Shadowbox.init({
        animate: true,
        handleOversize: 'drag',
        modal: true,
        onOpen: scrollBackground, onClose: scrollBackground 
    });
    
    function scrollBackground() { 
        // v1.1 Disables background screen scrolling while viewing shadowbox popups 

        // Copyright 2010 Peter Smith - The Science Registry 
        // Usage: Allowed if copyright statement remains 

        // add the following to the Shadowbox.init ({}) 
        // onOpen: scrollBackground, onClose: scrollBackground 

        // Get a reference to the HTML element 
        var objHTML = document.getElementsByTagName("html").item(0); 

        // Hide/show scrollbar 
        if (objHTML.style.overflow == "hidden") { 
            objHTML.style.overflow = "auto"; 
            $(window).scrollTop(_scrollTop); 
        } else { 
            _scrollTop = $(window).scrollTop(); 
            objHTML.style.overflow = "hidden"; 
            // Hiding the vertical scrollbar and having the webpage centered makes the content jump across by the amount of the scrollbars width 
            // this adjust that if html width is not set i.e. it only fires once. 
            if (objHTML.style.width == "") objHTML.style.width = "" + parseInt(objHTML.offsetWidth - 17) + "px"; 
        } 
    }
    
    
    if ($('#flash').length > 0){
        swfobject.embedSWF('/swf/header.swf', 'flash', '990', '230', '10');
    }
    $('#send').click(function(){
        $('#form').submit();
        return false;
    });
    $('#send2').click(function(){
        $('#form2').submit();
        return false;
    });
    $('.onchange_submit').change(function(){
        $('#form').submit();
        return false;
    });
    $('#form').keypress(function(event) {
        if (event.which == '13') {
            $('#form').submit();
            return false;
        }
    });
    $('.false').click(function(){
        return false;
    });    
    $('#searchword').blur(function(){
        if($(this).val() == '' ){
            $(this).val('buscar producto');
        }
    });
    $('#searchword').focus(function(){
        if($(this).val() == 'buscar producto' ){
            $(this).val('');
        }
    });
    $('#nav li').hover(
        function () {
            $('ul', this).slideDown(0);

        },  
        function () {
            $('ul', this).slideUp(0);
        });
    $('.accordion ul').hide();
    $('.accordion p').click(function(){
        $(this).next('ul').slideToggle('slow')
        .siblings('ul:visible').slideUp('slow');
        $(this).toggleClass('active');
        $(this).siblings('p').removeClass('active');
    });
    $('#subtipo_id').change(function(){
        var location = document.location.href;
        location = location.replace(/\&subtipo_id=[0-9]+/g, '');
        if ($(this).val() && ($(this).val()  != '0')){
            document.location.href = location + '&subtipo_id=' + $(this).val();
        }
        else{
            document.location.href = location;
        }
        return false;
    });    
    $('.data li:even').addClass('two');    
    $('.change_image').click(function(){
        $('#list_images li').removeClass('active');
        $(this).parent().addClass('active');
        $('#target_image').attr('src', $(this).attr('href'));
        return false;
    });       
});
