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

function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));
    return baseURL;
}

function gotoGame (p_box){
    if(p_box.value != "noGame")
    {
        var theUrl = getBaseURL();
        var gamesLink = "/game/";
        var theFullLink = theUrl + gamesLink + p_box.value;
        window.location.href = theFullLink;
    }
}

function reloadGamesList (p_box){
    if(p_box.value != "noCategory")
    {
        var theUrl = getBaseURL();
        var gamesLink = "/gameslist/?category=";
        var theFullLink = theUrl + gamesLink + p_box.value;
        window.location.href = theFullLink;
    }
}

function sortOnAlphabet (p_tabID){
    var tabId = p_tabID;
    $(tabId +' h2 a').click(function(){ //When any link is clicked
        var theUrl = getBaseURL();
        var gamesLink = "/gameslist/";
        var theExtra = window.location.search;
        var alphabetical = 'ascending';
        var theFullLink = '';
        if(theExtra != ''){
            var catmatch = theExtra.match("category");
            var alphamatch = theExtra.match("alphabetical");
            var amp = theExtra.indexOf("&");
            if(amp == -1){
                var category = theExtra.substr(0, theExtra.length);
            }else{
               var category = theExtra.substr(0, amp);
            }
            if(catmatch == null && alphamatch == null){
                theFullLink = theUrl + gamesLink + theExtra +"?alphabetical=click";
            }else if (catmatch == null && alphamatch != null){
                theFullLink = theUrl + gamesLink + "?alphabetical=click";
            }else if(catmatch != null && alphamatch != null){
                theFullLink = theUrl + gamesLink + category +"&alphabetical=click";
            }else if(catmatch != null && alphamatch == null){
               theFullLink = theUrl + gamesLink + category + "&alphabetical=click";
            }else{
               theFullLink = theUrl + gamesLink + "?alphabetical=click";
            }
        }else{
            theFullLink = theUrl + gamesLink + "?alphabetical=click";
        }
        window.location.href = theFullLink;
    });
}

function loadReview (p_url){
        window.location.href = p_url;
}

function loadGame (p_url){
       window.location.href = p_url;
}

function ToggleThatDiv(p_divId, p_visibility, p_display) {
if(document.getElementById) {
divs = document.getElementById(p_divId);
divs.style.visibility = p_visibility;
divs.style.display = p_display;
}
}

function ToggleThatColor(p_divId, p_bgcolor, p_revert) {
if(document.getElementById) {
divs = document.getElementById(p_divId);
divss = document.getElementById(p_revert);
divs.style.backgroundColor = p_bgcolor;
divss.style.backgroundColor = '#333333';

}
}

function showFB()
{
    ToggleThatDiv('socialtab-1', 'visible', 'block');
    ToggleThatDiv('socialtab-2', 'hidden', 'none');
    ToggleThatColor('home_button_social-1', '#bb2181', 'home_button_social-2');


}
function showTW()
{
    ToggleThatDiv('socialtab-2', 'visible', 'block');
    ToggleThatDiv('socialtab-1', 'hidden', 'none');
    ToggleThatColor('home_button_social-2', '#bb2181', 'home_button_social-1');

}

function bookmarkthi22s(title,url) {
  if (window.sidebar) { // firefox
     window.sidebar.addPanel(title, url, "");
  } else if (document.all) { // IE
     window.external.AddFavorite(url, title);
  } 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();
  }
}

function bookmarksite(title, url){
                    if (document.all)
                        {
                            window.external.AddFavorite(url, title);
                        }
                    else if (window.sidebar)
                        {
                        window.sidebar.addPanel(title, url, "");
                    }
                    else {
                        alert("Press CTRL-D (Chrome) or CTRL-T (Opera) to bookmark");
                    }
                }

                function bookmarkthis(title,url) {
                    bookmarksite(title, url);
                }
/*

$(document).ready(function()
{
   $("#playwidegame").colorbox({close:"Hide",scrolling:false, inline:true, href:"#widegame"});
   $("#twitterbackOpener").colorbox({width:"550px",close:"Hide",scrolling:false, inline:true, href:"#twitterbackText"});
});
*/