$(document).ready(function() {
    $("a[rel~='external']").attr('target', '_blank');
    $("a[rel~='nofollow']").mouseover(function(){
        window.status=this.title;
        return true;
    });
    $("a[rel~='nofollow']").mouseout(function(){
        window.status='';
        return true;
    });
});

//slider
$(document).ready(function() {
    try
    {
        gameObjectWidth = parseInt($("#gameObject").css("width"));
        gameObjectHeight = parseInt($("#gameObject").css("height"));
        wrapperWidth = parseInt($("#wrapper").css("width"));
        gameBlockWidth = parseInt($(".game-block").css("width"));
        sidebarWidth = parseInt($(".sidebar").css("width")) + 40; // + 40px padding #wrapper
        maxGameObjectWidth = gameBlockWidth - 20; // - 20px padding .game-block

        var game = new Game(gameObjectWidth, gameObjectHeight, wrapperWidth, gameBlockWidth, sidebarWidth, maxGameObjectWidth);
        game.initSize();
    }
    catch (e) {}

    $('#slider').slider({
        values: [50]
    });
    
    $('#slider').bind('slidechange', function(event, ui) {
        multiplySize = $('#slider').slider('option', 'values') * 2 / 100;
        game.resize(multiplySize);
    });
});

//magnify image and remove title
$(document).ready(function() {
    try
    {
        //$(".games a").attr('title', '');
        $(".games a").easytooltip("tooltip");
        $(".games a").hover(function() {
				$("#tooltip").html('<img src="/img/thumbs/' + $(this).attr('rel') + '.jpg" alt="' + $(this).html() + '" />');
        });
    }
    catch(e) {}
});

//stars rating
$(document).ready(function() {
    $("#stars-wrapper").stars({
        oneVoteOnly: true,
        captionEl: $('#stars-cap'),
        callback: function(ui, type, value){
            $.ajax({
                type: "POST",
                url: "game",
                data: 'action=updateRating&rating=' + value + '&gameId=' + $("#gameId").val(),
                success: function(msg){
                    alert('Je heeft een ' + value + ' voor dit spel gegeven. Bedankt voor je waardering!');
                }
            });
        }
    }); 
});

function bookmark(url, title)
{
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) // opera
    {
        var elem = document.createElement('a');
        elem.setAttribute('href',url);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
    }
    else if(document.all) // ie
        window.external.AddFavorite(url, title);
}


function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
            offset += search.length
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1)
                end = document.cookie.length;
            returnvalue=unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}

function loadpopunder(){
    popunder = window.open("http://www.hypotheeklenen.com/geld-lenen-zonder-bkr-toetsing","","width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0");
    popunder.blur();
    window.focus();
}

//var once_per_session = 1;
//$(document).ready(function() {
//    $('body').click(function() {
//        if (once_per_session==0) {
//            loadpopunder()
//        }
//        else {
//            if (get_cookie('popunder') == ''){
//                loadpopunder();
//                document.cookie="popunder=yes";
//            }
//        }
//    });
//});
