/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function rollover(img,src)
{
    if(src.length>0) {
        img.src=src;
    }
}

function rollout(img,src)
{
    if(src.length>0) {
        img.src=src;
    }
}

$(function(){
    //    if($(window).height()<$("#container").height()) {
    //        $("#container").css({
    //            "margin-top": "0px",
    //            "top":"5px"
    //        });
    //    }

    $("ul.menu li ul").hide();
    $("#product_menu ul li").hover(function() {
        $(this).children('ul').fadeIn();
    },function() {
        $(this).children('ul').fadeOut();
    });

    $('.form.adauga').submit(function() {
        return false;
    })

    $(".add_fav").click(
        function() {
            $.ajax({
                url: $(this).attr('href'),
                data: "",
                success: function(raspuns) {
                    $("#wishlist_add").html(raspuns);
                }
            });
            return false;
        })

    $(".adauga_link").click(

        function() {
            form=$(this).parent();
            $('#final').hide();
            $('#status').show();
            data="cantitate=" + form[0].cantitate.value
            + "&id_produs=" + form[0].id_produs.value
            + "&marime=" + form[0].marime.value
            ;
            $.ajax({
                url: form.attr('action'),
                data: data,
                success: function(raspuns) {
                    $('#final').html(raspuns);
                    $('#final').show();
                    refreshCos();
                    
                }
            });
        })

    function getRaspuns(str) {
        re=/<raspuns>[\w\s]*<\/raspuns>/;
        raspuns=str.match(re);
        return raspuns[0].replace(/<raspuns>/,'').replace(/<\/raspuns>/,'');
    }

    function refreshCos() {
        culture=
        $.ajax({
            url: "/" + $('#id_produs').attr('title') + '/cart-rezumat',
            data: '',
            success: function(raspuns) {
                $('#cart_rezumat').html(raspuns);
            }
        })

        $.ajax({
            url: "/" + $('#id_produs').attr('title') + '/cart-detaliat',
            data: '',
            success: function(raspuns) {
                $('#cart_content').html(raspuns);
            }
        })
    }
if($('#search_keywords').length) {
    if($('#search_keywords').attr('value').length==0) {
        $('#search_keywords').attr('value',$('#search_keywords').attr('title'));
    }

    $("#search_keywords").click(function(){
        if($('#search_keywords').attr('value')==$('#search_keywords').attr('title')) {
            $(this).attr('value','');
        }
    })
    $("#search_keywords").focusout(function(){
        if($('#search_keywords').attr('value').length==0) {
            $('#search_keywords').attr('value',$('#search_keywords').attr('title'));
        }
    })
}
    //    $(document).bind("contextmenu", function(e) {
    //
    //        $('#right_click_menu').css({
    //            top: e.pageY+'px',
    //            left: e.pageX+'px'
    //        }).show();
    //
    //        return false;
    //
    //    });
    //
    //
    //    $('#right_click_menu').click(function() {
    //        $('#right_click_menu').hide();
    //    });
    //    $(document).click(function() {
    //        $('#right_click_menu').hide();
    //    });

    $('#accordion li').children('ul').hide();
    $('#accordion li a.menu_title').click(function () {
        li=$(this).parent('li');
        if(li.hasClass('accorded')) {
            li.children('ul').slideUp('fast');
            li.removeClass('accorded');
        } else {
            $('#accordion li').removeClass('accorded');
            $('#accordion li').children('ul').slideUp('fast');
        
            li.children('ul').slideDown('fast');
            li.addClass('accorded');
        }
    });


});



