/*jslint strict:true, evil: true, onevar: true, nomen: false  */ /*global $, jQuery, console, hbx, window, ndm, document  */

"use strict";

jQuery.fn.CG_getBrowser = function(){
    var browser = "";

    if($.browser.msie){ browser = "ie"; }
    if($.browser.safari){ browser = "safari"; }
    if($.browser.opera){ browser = "opera"; }
    if($.browser.mozilla){ browser = "ff"; }

    if(navigator.userAgent.indexOf("Chrome") !== -1){
           browser = "Chrome";
    }
    return browser + $.browser.version;
};

jQuery.fn.CG_addHoverClass = function(classPrefix){
    $(this).hover(
        function(){
            $(this).addClass(classPrefix + "_hover");
        },
        function(){
            $(this).removeClass(classPrefix + "_hover");
        }
    );
};

jQuery.fn.CG_addAccessibility = function(sizeAdjustFactor){
    $(this).click(function(){
        $("#content").children().each(function(){
            var curFontSize = $(this).css("fontSize");
            var pxlFontSize="";

            if(curFontSize === "984px"){
                curFontSize = "12px";
            }

            if(curFontSize.indexOf("px") !== -1){
                pxlFontSize = parseInt(curFontSize.substring(0,curFontSize.length-2),10);
                $(this).css("fontSize",pxlFontSize+sizeAdjustFactor+"px");
            }
        });
    });
};

jQuery.fn.CG_setRandomFontSize = function(){
    $(this).each(function(){
        /* Minimum 10px and Maximum 18px */
        var randomFontSize = Math.floor(Math.random()*8)+10;
        $(this).css("font-size",randomFontSize+"px");
    });
};

function stopPropagation(e){
    e=e||event;
    e.stoppropagation ? e.stoppropagation() : e.cancelBubble=true;
}

jQuery.fn.CG_invokePopup = function(pURL,options,dynamicContent,printWin) {
    /* Creates a popup of a specific size and height in the center of the window */
    popupParams = jQuery.extend({
        width:860,
        height:725,
        left:(screen.availWidth - 860)/2,
        top:(screen.availHeight - 720)/2,
        winName:"CG_pWin",
        toolbar:1,
        scrollbars:1,
        menubar:1,
        location:1,
        resizable:"yes",
        titlebar:1,
        statusbar:1
    },options||{});

    CG_pWin = window.open(pURL,popupParams.winName,'width='+popupParams.width+',height='+popupParams.height+',top='+popupParams.top+',left='+popupParams.left+',toolbar='+popupParams.toolbar+',scrollbars='+popupParams.scrollbars+',menubar='+popupParams.menubar+',location='+popupParams.location+',resizable='+popupParams.resizeable+',titlebar='+popupParams.titlebar+',status='+popupParams.statusbar);
    CG_pWin.focus();

    if(dynamicContent && dynamicContent !== ""){
        CG_pWin.document.open();
        CG_pWin.document.write(dynamicContent);
        CG_pWin.document.close();
    }

    if(printWin){
        CG_pWin.print();
    }
};
