$(document).ready(function(){
    /*
    readCookiesAndSetDisplayCurrency();
    readCookiesAndSetFilter();
    */

    if (document.getElementById("featured-box-static") && document.getElementById("featured-box-animated")){
        var d = document.getElementById("featured-box-static");
        d.style.display = "none";
        var d = document.getElementById("featured-box-animated");
        d.style.display = "block";
    }

    $('#slider-pagination').jFlow({
        slides: "#slides",
        width: 740,
        height: 100,
        delay: 8000
    });
    /**
    $("#keyword").click(function(e){
        if ($(this).val() != '') $(this).val('');
    });
**/
    /**
     *autocomplete for keyword search field (frontend)
     */
    $("#keyword").autocomplete({
        source: "/games/lookupgame",
        select: function(event, ui) {
            $.get('/games/getdetailpageurl/?pid='+ui.item.id,
                function(data){
                    window.location.href = data;
                }
                );
        },
        delay: 10,
        minLength: 3
    }).keypress(function(e) {
        if (e.keyCode === 13)
        {
            window.location.replace('/search/all/term/'+$(this).val());
        }
    });

    $('.btn-search').click(function(){
        var $key = $('#keyword');
        if($.trim($key.val()).length) {
            window.location.replace('/search/all/term/'+$.trim($key.val()));
        }
        return false;
    });

    $('.postRating > a').click(function(e) {
        e.preventDefault();
        var id = $(this).parent().attr('id').substring(6);
        var msg = "";
        var element = $(this).parent().hasClass('vote');
        $.post(
            "/deals/rate/id/" + id,
            {rating: $(this).html()},
            function(xml) {
                if (element == true) {
                    msg = "Thanks!";
                } else {
                    msg = "("+xml+")";
                }
                $("#rating" + id).html(msg);
            }
        );
    });

    /*
    $('#of-reset').click(function(e){
        e.preventDefault();
        cookiejar.crumble('offerfilter');
        $("li[id^='of_']").removeAttr('class');
        $('.of-menu li').removeAttr('class');
        $('#of-reset').removeAttr('class');
        location.reload();
    });
    $('.of-update').click(function(e){
        e.preventDefault();
        location.reload();
    });
    $('.of-menu li').click(function(e){
        e.preventDefault();
        offerFilterItemSelected(this.id, e.target.id);
        location.reload();
    });

    $('#curselect').change(function(){
        var oldCur = cookiejar.fetch('displaycurrency');
        var newCur = $('#curselect').val();
        if (oldCur != newCur) {
            cookiejar.bake('displaycurrency', newCur, 3);
            location.reload();
        }
    });
    */

    $(".adminbuttons-menu").hover(
        function() {
            $(this).children("ul").show();
        },function() {
            $(this).children("ul").hide();
        });
        
    $(".showcommentfeed").click(
        function () {		
           if (document.getElementById('commentfeedbox').style.display == "none") {
                document.getElementById('commentfeedbox').style.display = "inherit";
                document.getElementById('commentfeedlink').innerHTML = "Hide comment feed";
           } else {
               document.getElementById('commentfeedbox').style.display = "none";
               document.getElementById('commentfeedlink').innerHTML = "Show comment feed";
           }
           
    });     
    
    
    $('.dropdownbutton').each(function(){
        var $this = $(this);        
        var pid = $this.attr('id');
        
        $(this).qtip({                       
            content: {url: '/user/wishlist/check/pid/'+pid},            
            show: 'mouseover',
            hide: {
                when: 'click || mouseout',
                fixed: true
            }, 
            style: 'dropdownButtonContent',
            position: {
                corner: {
                    target: 'leftBottom',
                    tooltip: 'leftTop'
                }
            }
        });
    });
    
    $('.dropdownbutton-collection').each(function(){
        var $this = $(this);        
        var poid = $this.attr('id');
        
        $(this).qtip({                       
            content: {url: '/user/collection/check/poid/'+poid},            
            show: 'mouseover',
            hide: {
                when: 'mouseout',
                fixed: true
            }, 
            style: 'dropdownButtonCollectionContent',
            position: {
                corner: {
                    target: 'leftBottom',
                    tooltip: 'leftTop'
                }
            }
        });
    });
    
        
});
