var wibiya_pl = "true";
var wibiya_nc = "false";
var wibiya_latestJq = false;
var wibiya_jQuery_ver = 132;
var wibiyaTimeoutId;

function jquery_ver(){
    return parseInt(jQuery.fn.jquery.replace(/\./gi,'').substring(0,3));
}

function loadjscssfile(filename, filetype, where){
    var fileref;
    if (filetype=="js"){ //if filename is a external JavaScript file
        fileref=document.createElement("script");
        fileref.setAttribute("type","text/javascript");
        fileref.setAttribute("src", filename);
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        fileref=document.createElement("link");
        fileref.setAttribute("rel", "stylesheet");
        fileref.setAttribute("type", "text/css");
        fileref.setAttribute("href", filename);
    }
    if (typeof fileref!="undefined"){
        if (where=="head"){
            document.getElementsByTagName("head")[0].appendChild(fileref);
        }
        else{
            document.getElementsByTagName("body")[0].appendChild(fileref);
        }
    }
}

function CheckJQueryLoader(toolbarId)
{
    if (typeof jQuery == "function")
    {
        if (!wibiya_latestJq)
        {
            clearTimeout(wibiyaTimeoutId);
            SetToolbarLoad();
        }
        else
        {
            if (jquery_ver() >= wibiya_jQuery_ver)
            {
                clearTimeout(wibiyaTimeoutId);
                SetToolbarLoad();
            }
            else
            {
                wibiyaTimeoutId =  setTimeout("CheckJQueryLoader("+toolbarId+");",200);
            }
        }
    }
    else
    {
        wibiyaTimeoutId =  setTimeout("CheckJQueryLoader("+toolbarId+");",200);
    }
}

function querySt(ji)
{
    var hu = window.location.search.substring(1);
    var gy = hu.split("&");
    for (i=0;i<gy.length;i++)
    {
        var ft = gy[i].split("=");
        if (ft[0] == ji)
        {
            return ft[1];
        }
    }
}

function SetToolbarLoad(){
    var wibiya_mobiles = ["ipad","iphone","ipod","series60","symbian","android","windows ce",
        "blackberry","palm","avantgo","docomo","vodafone","j-phone",
        "xv6850","htc","lg;","lge","mot","nintendo","nokia","samsung","sonyericsson"];
    wibiyaToolbar.wibiya_isMobile = false;
    wibiyaToolbar.wibiya_uAgent = navigator.userAgent.toLowerCase();
    for(var i=0;i<wibiya_mobiles.length;i++){
        if(wibiyaToolbar.wibiya_uAgent.match(wibiya_mobiles[i]) != null){
            wibiyaToolbar.wibiya_isMobile = true;
            break;
        }
    }

    if ((jQuery.browser.msie) ||  wibiyaToolbar.wibiya_isMobile == true){
        // ie 6 and below -> do nothing
    }
    else{
        wibiyadomain = "http://cdn.wibiya.com/Toolbars/dir_0340/Toolbar_340360/";
        // no-conflict
        if (wibiya_nc=="true") jQuery.noConflict();

        // detect jd_gallery, ie, user_request - load page after document.ready
        if (typeof (startGallery) == "function" || jQuery.browser.msie || wibiya_pl=="true")
        {
            jQuery(document).ready(function(){
                if (typeof (querySt("toolbarObjId")) == "undefined")
                {
                    var wibiyaScriptSrc = wibiyadomain+"toolbar_340360_4be97ef267641.js";
                }
                else
                {
                    var wibiyaScriptSrc = wibiyadomain+querySt("toolbarObjId")+".js";
                }
                loadjscssfile(wibiyaScriptSrc,"js","body");
            });
        }
        else
        {
            if (typeof (querySt("toolbarObjId")) == "undefined")
            {
                var wibiyaScriptSrc = wibiyadomain+"toolbar_340360_4be97ef267641.js";
            }
            else
            {
                var wibiyaScriptSrc = wibiyadomain+querySt("toolbarObjId")+".js";
            }
            loadjscssfile(wibiyaScriptSrc,"js","body");

        }
    }
}

if (typeof(wibiyaToolbar)!="object"){

    if ( typeof jQuery != "function")
    {
        loadjscssfile("http://cdn.wibiya.com/Scripts/jquery-1.4.2.min.js","js","head");
    }
    else
    {
        if (wibiya_latestJq && jquery_ver() != wibiya_jQuery_ver)
        {
            loadjscssfile("http://cdn.wibiya.com/Scripts/jquery-1.4.2.min.js","js","head");
        }
    }


    var wibiyaToolbar = {};
    wibiyaToolbar.id="340360";
    wibiyaToolbar.referrer=document.referrer;
    CheckJQueryLoader(wibiyaToolbar.id);
}