﻿if (typeof (jQuery) == "undefined") {
    document.write("<scr" + "ipt src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'></scr" + "ipt>");
}

if (typeof(Constants)=="undefined")
	Constants=new Object();

Constants.isIE = navigator.appName.toLowerCase().indexOf("explorer") > -1;
String.prototype.trim = function(){    return this.replace(/^\s{1,}/ig, "").replace(/\s{1,}$/ig, "");}

function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function BannerSliderObj() 
{
    this.open = function(forceOpen) {
        if (this.doNotShowAgain() && !forceOpen)
            return;

        LogStats = true;

        if (divBannerSlider.style.display == "none")
            divBannerSlider.style.display = "";

        if (Sliderbehavior.SliderBottomSpace == null) {
            Sliderbehavior.SliderBottomSpace = document.createElement("div");
            Sliderbehavior.SliderBottomSpace.innerHTML = "&nbsp;";
            Sliderbehavior.SliderBottomSpace.style.marginTop = "0px";
            Sliderbehavior.SliderBottomSpace.style.height = "0px";
            Sliderbehavior.SliderBottobSpaceBR = document.createElement("br");
            Sliderbehavior.SliderBottobSpaceBR.setAttribute("clear", "all");
            Sliderbehavior.SliderBottobSpaceBR.style.lineHeight = "1px";
            document.body.insertBefore(Sliderbehavior.SliderBottomSpace, document.body.firstChild);
            document.body.insertBefore(Sliderbehavior.SliderBottobSpaceBR, Sliderbehavior.SliderBottomSpace.nextSibling);
        }

        Sliderbehavior.SliderBottomSpace.style.display = "";
        if (parseInt(divBannerSlider.style.top, 10) < 0) {
            divBannerSlider.style.top = parseInt(divBannerSlider.style.top, 10) + 2 + "px";
            Sliderbehavior.SliderBottomSpace.style.height = parseInt(Sliderbehavior.SliderBottomSpace.style.height, 10) + 2 + "px";
            window.setTimeout("BannerSlider.open(" + forceOpen + ");", 15);
        }
        else {
            if (parseInt(divBannerSlider.style.top, 10) > 0)
                divBannerSlider.style.top = "0px";
                
            Sliderbehavior.SliderBottomSpace.style.height = parseInt(Sliderbehavior.SliderBottomSpace.style.height, 10) - 2 + "px";
            //divBannerSlider.style.height = "auto";
        }

    }

    this.close = function() {
        if (parseInt(divBannerSlider.style.top, 10) > -1 * divBannerSlider.clientHeight) {
            divBannerSlider.style.top = parseInt(divBannerSlider.style.top, 10) - 2 + "px";
            if (Sliderbehavior.SliderBottomSpace != null) {
                Sliderbehavior.SliderBottomSpace.style.height = parseInt(Sliderbehavior.SliderBottomSpace.style.height, 10) - 2 + "px";
            }
            window.setTimeout("BannerSlider.close();", 15);
        }
        else {
            divBannerSlider.style.display == "none";
            Sliderbehavior.SliderBottomSpace.style.height = "0px";
            Sliderbehavior.SliderBottomSpace.style.display = "none";
        }
    }

    this.init = function() {
        if (divBannerSlider.style.display == "none")
            divBannerSlider.style.display = "";

        divBannerSlider.style.background = "url('" + Constants.sliderImgPath + "') no-repeat center top";
        var sliderTImages = divBannerSlider.getElementsByTagName("img");
        var i;
        for (i = 0; i < sliderTImages.length; i++) {
            sliderTImages[i].setAttribute("src", Constants.transparentImg);
        }

        divBannerSlider.style.top = (-1 * divBannerSlider.clientHeight - 2) + "px";
    }

    this.setDoNotShowAgain = function()
    {
        this.close();
        //document.body.innerHTML+="<iframe src=\"" + adrSetCookie + "\"></iframe>";
        //document.body.innerHTML+="<object><param name=\"movie\" value=\"" + adrSetCookie + "\"><embed src=\"" + adrSetCookie + "\"></embed></object>"
        Set_Cookie( "toolbarhome_top_slider", "true", 60, "/");
    }
    
    this.doNotShowAgain = function() {return eval(Get_Cookie( "toolbarhome_top_slider")) }

    this.init();
}

var Sliderbehavior = {
    SliderBottomSpace: null,
    SliderBottobSpaceBR : null

}

function initialize() {
	 // quit if this function has already been called
     if (arguments.callee.done) return;

     // flag this function so we don't do the same thing twice
     arguments.callee.done = true;
 
	Set_Cookie( 'CookieEnabled', 'none', '', '/', '', '' );
	
	if ( Get_Cookie( 'CookieEnabled' ) )			// user supports cookies
	{
		Delete_Cookie('CookieEnabled', '/', '');				
	}
	wireSmartObjects();
}

function wireSmartObjects(container) {
	container=(container==null ? this.element : container)
	
	var smartObj=getElementsByCondition(function(el){return (el.getAttribute("smartid")!=null);}, container);
	for (var i=0; i<smartObj.length; ++i)
	{
		eval("this."+smartObj[i].getAttribute("smartid")+"=smartObj[i]");		
	}
	
	for (var i=0; i<smartObj.length; ++i)
	{
		if (smartObj[i].getAttribute("smartinit")!=null)
		{
		    var s_this=smartObj[i];
			eval(smartObj[i].getAttribute("smartinit"));
		}
	}	
}

function getElementsByCondition(condition,container)
{
	container = container||document
	var all = container.all || container.getElementsByTagName('*')
	
	var arr = []
	for(var k=0;k<all.length;k++)
	{		
		var elm = all[k]
		
		if (elm.nodeType!=1)
			continue;



        //if (elm.className == "srHelpful")
            //alert(condition);
            
        if (condition(elm, k)) {
                arr[arr.length] = elm

            }
	}
	
	return arr
} 

/// Cookies handling /////////////////////////////////////////

// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

document.write("<style type='text/css'>");
document.write("#bgHide{top:0px; left:0px; position: fixed; width:100%; height:100%; z-index:1000000; background-color:gray; filter:alpha(opacity=40); -moz-opacity:0.4; -khtml-opacity: 0.4; opacity: 0.4;}");
document.write(".downloadarrowBg{position:fixed; text-align:right; right:5px; top:5px; z-index:2000000; border:0px;}");
document.write(".downloadarrow{position:fixed; text-align:right; right:40px; top:10px; z-index:2000000; border:0px;}");
document.write(".fadeout{display: block; text-decoration: none; font-weight:bold; font-size: 12px; height: 16px; position: fixed; top: 5px; right: 5px; color: White;}");
document.write("</style>");
 
document.write("<div id='bgHide' style='display: none;'></div>");
document.write("<img src='" + DOWNLOAD_HELPER_IMAGE_URL + "' class='downloadarrowBg' id='downloadHelper' style='display: none;' usemap='#download_helper' />");
if (DOWNLOAD_HELPER_ARROW_URL != "") {
    document.write("<img src='" + DOWNLOAD_HELPER_ARROW_URL + "' class='downloadarrow' id='downloadHelperArrow' style='display: none;' />");
}
document.write("<map id='download_helper' name='download_helper'><area shape='rect' alt='Close' coords='" + DOWNLOAD_HELPER_CLOSE_CORDS + "' nohref title='Close' onClick='fadeout();' href='#' /></map>");

var DownloadHelperIsOpen = false;

function downloadEvent() {
    jQuery(document).keydown(function(e) {
	    if (e.which == 27 && DownloadHelperIsOpen) {  // escape, close box
	        fadeout();
	    }
	});	
	
    DownloadHelperIsOpen = true;
    jQuery('#bgHide').fadeIn('slow');
    jQuery('#downloadHelper').fadeIn('slow');
    jQuery('#downloadHelperArrow').fadeIn('slow');
}

function fadeout() {
    DownloadHelperIsOpen = false;
    jQuery('#bgHide').fadeOut('slow');
    jQuery('#downloadHelper').fadeOut('slow');
    jQuery('#downloadHelperArrow').fadeOut('slow');
    
}

function closeEvent()
{
    if (typeof trackCloseEvent == 'function')
        trackCloseEvent();
}

function dontShowEvent()
{
    if (typeof trackDontShowEvent == 'function')
        trackDontShowEvent();
}

function adClick()
{
    if (typeof trackAdClick == 'function')
        trackAdClick();

    if (USE_LANDING_PAGE)
        return;

    if (jQuery.browser.mozilla) 
        downloadEvent();
}


