function vbn_getCookies() {
	var hash = new Array;
	if ( document.cookie ) {
		var cookies = document.cookie.split( '; ' );
		for ( var i = 0; i < cookies.length; i++ ) {
			var namevaluePairs = cookies[i].split( '=' );
			hash[namevaluePairs[0]] = unescape( namevaluePairs[1] ) || null;
		}
	}
	return hash;
}

function vbn_parseCookieData( cookieDataString ) {
	var cookieValues = new Object();
	var separatePairs = cookieDataString.split( '&' );
	for ( var i = 0; i < separatePairs.length; i++  ) {
		var separateValues = separatePairs[i].split( ':' );
		cookieValues[separateValues[0]] = separateValues[1] || null;
	}
	return cookieValues;
}

function vbn_setCookie( name, value, hours, path, domain, secure ) {
		var numHours = 0;

		if ( hours) {
			if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
				numHours = hours;
			} else if ( typeof(hours) == 'number' ) { // calculate Date from number of hours
				numHours = ( new Date((new Date()).getTime() + hours*3600000) ).toGMTString();
			}
		}

		document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.

}


function vbn_killCookie( name, path, domain ) {
	var allCookies = vbn_getCookies();

	var theValue = allCookies[ name ] || null; // We need the value to kill the cookie
	if ( theValue ) {
		document.cookie = name + '=' + theValue + '; expires=Fri, 18-Apr-1978 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
	}
}


var allCookies = vbn_getCookies();

/* breaking news banners
=========================================================================== */
function vbnRenderGenericBanner(object,flashURL,leftColor,rightColor)
{
	if (allCookies['vbnLastClosedBannerId'] == object.id)
	{
		// don't render anything if the banner has been closed.
		return '';
	}

	var myHtml = '<div id="vbnBannerContent"><div id="vbnBannerTopic" class="'+leftColor+'">';

	if (!(object.type == 'Live Breaking News' || object.type == 'Live Developing Story') || !(new vbn_FlashDetect().detectVersion( 8 )))
	{
		myHtml += '<div id="vbnBannerHeader"><div id="vbnBannerHeaderTxt">'+object.title+'<\/div><\/div>';
	}
	else
	{
		leftColor = 'vbnTransparent';// put transparency behind swf files
		myHtml = '<div id="vbnBannerContent"><div id="vbnBannerTopic" class="'+leftColor+'">';
		var vbn_AnimatedBanner = new vbn_FlashObject( "vbnAnimatedBannerTitle", flashURL, 211, 73, null, { bn_title: object.title } );
		myHtml += vbn_AnimatedBanner.getHtml();
	}

	myHtml += '<\/div><div id="vbnBannerBox" class="'+rightColor+'">';
	myHtml += '<div id="vbnBannerBoxContent"><a href="#" onMouseOver="vbnImgSwap(this,1);" onMouseOut="vbnImgSwap(this,0);" onClick="vbn_setCookie(\'vbnLastClosedBannerId\',\''+object.id+'\'); $(\'vbnBannerContainer\').hide(); return true;"><img class="vbnCloseBtn" name="vbnBannerCloseBtn" src="/news/images/vbn_'+rightColor.substring(3).toLowerCase()+'_btn.gif" width="14" height="14" alt="" /><\/a>';

	if ((object.type == 'Live Breaking News' || object.type == 'Live Developing Story' || object.type == 'Live Election Coverage') && object.image.length > 0)
	{
		myHtml += '<img class="vbnBannerPhoto" src="'+object.image+'" width="87" height="49" alt="" />';
	}
	
	myHtml += '<div id="vbnBannerHeadline"';
	if (object.size == 'small')
	{
		myHtml += ' class="small"';
	}
	myHtml += '>'+object.content;
	if((object.options) && (object.options != '') && (object.type == 'Breaking News')) {// email link
		myHtml += '<span class="vbnBnEmailLnk"><a href="http://audience.vbn.com/services/vbn/login.do?iref=BNemail&url=http%3A%2F%2Faudience.vbn.com%2Fservices%2Fvbn%2Fregwall%2Fmembercenter.do ">Get Breaking News by e-mail</a></span>';
	}
	myHtml += '<\/div>';
	if (object.pipe != 0 || object.tv != 0)
	{
		myHtml += '<div id="vbnBannerWatchNow">Watch Now: ';
		if (object.tv != 0)
		{
			myHtml += 'on SKNVibes.com TV';
			if (object.pipe != 0)
			{
				myHtml += ' <span class="vbnGreyTxt">or <\/span>';
			}
		}
		if (object.pipe != 0)
		{
			myHtml += '<a href="javascript:vbnLiveVideo(\''+object.pipe+'\');">Live on SKNVibes.com &raquo;<\/a>';
		}
		myHtml += '<\/div>';
	}

	myHtml += '<\/div><\/div><\/div><div class="vbnPad12Top" style="clear:both;"> <\/div>';

	return myHtml;
}

function vbnRenderDomesticBanner(object){
	var flashURL='/news/swf/bn_dom.swf';
	var leftColor='';
	var rightColor='';
	switch (object.type) {
		case 'Live Breaking News':leftColor='vbnRed';rightColor='vbnBlack';break;
		case 'Breaking News':leftColor='vbnBlack';rightColor='vbnRed';break;
		case 'Live Developing Story':leftColor='vbnYellow';rightColor='vbnBlack';flashURL='/news/swf/bn_dev.swf';break;
		case 'Developing Story':leftColor='vbnBlack';rightColor='vbnYellow';break;
		case 'Watch Now':leftColor='vbnBlue';rightColor='vbnBlue';break;
		case 'Live Election Coverage':leftColor='vbnBlackElex';rightColor='vbnDrkBlue';break;
		default:return '';
	}
	return vbnRenderGenericBanner(object,flashURL,leftColor,rightColor);
}

function vbnRenderInternationalBanner(object){
	var flashURL='/news/swf/bn_int.swf';
	var leftColor='';
	var rightColor='vbnYellow';
	switch (object.type) {
		case 'Live Breaking News':leftColor='vbnYellow';rightColor='vbnBlack';break;
		case 'Breaking News':leftColor='vbnBlack';break;
		case 'Live Developing Story':leftColor='vbnYellow';rightColor='vbnBlack';flashURL='/news/swf/bn_dev.swf';break;
		case 'Developing Story':leftColor='vbnBlack';break;
		case 'Watch Now':leftColor='vbnBlue';rightColor='vbnBlue';break;
		default:return '';
	}
	return vbnRenderGenericBanner(object,flashURL,leftColor,rightColor);
}

/* end breaking news banners
=========================================================================== */
var VBS_Result = false;

function vbnImgSwap( strId, intSwap ) {
	// assumes 2 images: image.gif and image_over.gif
	var imgObj = (typeof(strId) == "object") ? strId.getElementsByTagName('img')[0] : document.getElementById( strId );
	var strTemp = imgObj.src;
	var intStrLength = strTemp.length;
	var intChop, strEnd;

	if ( intSwap ) {
		if (strTemp.indexOf('_over.gif') == -1) {
			intChop = intStrLength - 4;
			strEnd = '_over.gif';
		}
	} else {
		if (strTemp.indexOf('_over.gif') > -1) {
			intChop = intStrLength - 9;
			strEnd = '.gif';
		}
	}

	if (typeof(intChop) != "undefined") {
		strTemp = strTemp.substring( 0, intChop );
	}

	if (typeof(strEnd) != "undefined") {
		imgObj.src = strTemp + strEnd;
	}
}

function vbn_FlashDetect() { }

vbn_FlashDetect.prototype.maxVersionToDetect = 8;
vbn_FlashDetect.prototype.minVersionToDetect = 3;

vbn_FlashDetect.prototype.hasPlugin = ( navigator.mimeTypes &&
		navigator.mimeTypes.length &&
		navigator.mimeTypes["application/x-shockwave-flash"] &&
		navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin );

vbn_FlashDetect.prototype.hasActiveX = window.ActiveXObject;

vbn_FlashDetect.prototype.hasWinIE = ( navigator.userAgent &&
		( navigator.userAgent.indexOf( "MSIE" ) != -1 ) &&
		navigator.appVersion &&
		( navigator.appVersion.indexOf( "Win" ) != -1 ) );

vbn_FlashDetect.prototype.getVersion = function () {
	var versionNum = 0;
	var i = 0;

	if ( this.hasActiveX ) {
		var activeXObject = false;
		for ( i = this.maxVersionToDetect; i >= this.minVersionToDetect && !activeXObject; versionNum = ( activeXObject ? i : versionNum ), i-- ) {
			try {
				activeXObject = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash." + i );
			} catch( e ) {
				// do nothing
			}
		}
	} else if ( this.hasWinIE ) {
		VBS_Result = false;
		for ( i = this.maxVersionToDetect; i >= this.minVersionToDetect && !VBS_Result; versionNum = ( VBS_Result ? i : versionNum ), i-- ) {
			execScript( 'on error resume next: VBS_Result = IsObject( CreateObject( "ShockwaveFlash.ShockwaveFlash.' + i + '" ) )', 'VBScript' );
		}
	} else if ( this.hasPlugin ) {
		if ( navigator.plugins && navigator.plugins.length && navigator.plugins["Shockwave Flash"] ) {
			var words = navigator.plugins["Shockwave Flash"].description.split( " " );
			for ( i = 0; i < words.length; ++i ) {
				if ( isNaN( parseInt( words[i] ) ) )
					continue;
				versionNum = words[i];
			}
		}
	}

	return ( versionNum );
}

vbn_FlashDetect.prototype.detectVersion = function ( num ) {
	var isVersionSupported = false;

	if ( ! isNaN( num ) ) {
		isVersionSupported = ( this.getVersion() >= parseInt( num ) );
	}

	return ( isVersionSupported );
}


function vbn_FlashObject( p_name, p_src, p_width, p_height, p_parameters, p_flashVars ) {
	this.m_name			= p_name;
	this.m_src			= p_src;
	this.m_width		= p_width;
	this.m_height		= p_height;
	this.m_flashVars	= p_flashVars;

// constructor
	if ( p_parameters )
	{
		this.setParams( p_parameters );
	}
}

// Declare member properties
vbn_FlashObject.prototype.m_name = '';
vbn_FlashObject.prototype.m_src = '';
vbn_FlashObject.prototype.m_width = '';
vbn_FlashObject.prototype.m_height = '';
vbn_FlashObject.prototype.m_flashVars = '';

vbn_FlashObject.prototype.m_params = {
	menu:		"false",
	quality:	"high",
	allowScriptAccess:		"always",
	wmode:		"transparent"

};

vbn_FlashObject.prototype.setParam = function ( p_name, p_value ) {
	this.m_params[ p_name ] = p_value;
}

vbn_FlashObject.prototype.setParams = function ( p_paramHash ) {
	if ( typeof p_paramHash == "object" ) {
		for ( var param in p_paramHash ) {
			if ( p_paramHash[param] ) {
				this.setParam( param, p_paramHash[param] );
			}
		}
	}
}

vbn_FlashObject.prototype.getParam = function ( p_name ) {
	return ( this.m_params[ p_name ] );
}

vbn_FlashObject.prototype.getParams = function () {
	return ( this.m_params );
}

vbn_FlashObject.prototype.getFlashVarsString = function () {
	var flashVarsString = '';

	if ( typeof this.m_flashVars == "string" ) {
		flashVarsString = this.m_flashVars;
	} else if ( typeof this.m_flashVars == "object" ) {
		for ( var flashVar in this.m_flashVars ) {
			if ( flashVarsString != '' ) {
				flashVarsString += "&";
			}
			flashVarsString += flashVar + "=" + escape( this.m_flashVars[flashVar] );
		}
	}

	return ( flashVarsString );
}

vbn_FlashObject.prototype.getAttributeString = function ( p_attr, p_value ) {
	return ( p_value ? ' ' + p_attr + '="' + p_value + '"' : '' );
}

vbn_FlashObject.prototype.getParamTag = function ( p_name, p_value ) {
	return ( p_value ? '<param name="' + p_name + '" value="' + p_value + '">' : '' );
}

vbn_FlashObject.prototype.getHtml = function () {
	var htmlString = '';
	var eachParam = '';
	var flashUrl = 'http://www.macromedia.com/go/getflashplayer';

// open object
	htmlString += '<object type="application/x-shockwave-flash" \
					classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	htmlString += this.getAttributeString( 'pluginspage', flashUrl );
	htmlString += this.getAttributeString( 'id', this.m_name );
	htmlString += this.getAttributeString( 'data', this.m_src );
	htmlString += this.getAttributeString( 'width', this.m_width );
	htmlString += this.getAttributeString( 'height', this.m_height );
	htmlString += '>';
	htmlString += this.getParamTag( 'movie', this.m_src );
	for ( eachParam in this.getParams() ) {
		htmlString += this.getParamTag( eachParam, this.getParam( eachParam ) );
	}
	htmlString += this.getParamTag( 'flashVars', this.getFlashVarsString() );

// open embed
	htmlString += '<embed type="application/x-shockwave-flash"';
	htmlString += this.getAttributeString( 'pluginspage', flashUrl );
	htmlString += this.getAttributeString( 'name', this.m_name );
	htmlString += this.getAttributeString( 'src', this.m_src );
	htmlString += this.getAttributeString( 'width', this.m_width );
	htmlString += this.getAttributeString( 'height', this.m_height );
	for ( eachParam in this.getParams() ) {
		htmlString += this.getAttributeString( eachParam, this.getParam( eachParam ) );
	}
	htmlString += this.getAttributeString( 'flashVars', this.getFlashVarsString() );
	htmlString += '>';

// close embed
	htmlString += '<\/embed>';

// close object
	htmlString += '<\/object>';

	return ( htmlString );
}

vbn_FlashObject.prototype.writeHtml = function () {
	document.write( this.getHtml() );
}

vbn_FlashObject.prototype.writeMosaicHtml = function (id) {
	document.getElementById(id).innerHTML =  this.getHtml();
}



/* styled overlay menus
=========================================================================== */
var vbnOverlayOpenId = "";
var vbnOverlayClickedId = "";
var vbnOverlayMenuOpen = false;

// Map menu id's to button classes, for determining later on if the current menu
// is one with non-default behavior.
var vbnOverlayClass = [];


function vbnInitOverlay() {
	document.body.onmousedown = vbnMouseDown;

	// Overlay menus with default behavior
	vbnAddOverlayEvents("vbnOverlayLnk");

	// Add code here for overlay menus with non-default behavior
}


function vbnShowOverlay(menuId) {
	if ($(menuId)) {
		// If the menu is already open, close it
		if ($(menuId).style.display == "block") {
			$(menuId).style.display = "none";
		}
		else {
			$(menuId).style.display = "block";
			vbnOverlayOpenId = menuId;
		    vbnOverlayMenuOpen = true;
			vbnOverlayClickedId = "";
		}
	}

	// Add code here for overlay menus with non-default behavior
}


function vbnHideOverlay(menuId) {
	if ($(menuId)) {
		$(menuId).style.display = "none";
		vbnOverlayOpenId = '';
	    vbnOverlayMenuOpen = false;
	}

	// Add code here for overlay menus with non-default behavior
}


function vbnGetOverlayMenuId(btn) {
	// Get the id parameter from href="javascript:foo('myId')"
	return btn.href.substring(btn.href.indexOf("'") + 1, btn.href.lastIndexOf("'"));
}


function vbnAddOverlayEvents(btnClass) {
	var btnArray = document.getElementsByClassName(btnClass);
	for (var i = 0; i < btnArray.length; i++) {
		// button
		var btn = btnArray[i];
		btn.onmousedown = vbnOverlayMouseDownBtn;

		// menu
		var menuId = vbnGetOverlayMenuId(btn);
		if ($(menuId)) {
			$(menuId).onmousedown = vbnOverlayMouseDownMenu;
		}

		// Store the button class associated with the menu id
	    vbnOverlayClass[menuId] = btnClass;

		// Mac Safari image-rollover bug
		if ((navigator.userAgent.indexOf("Safari") != -1)
		 && (navigator.userAgent.indexOf("Mac") != -1)) {
			// If vbnImgSwap() is called by the onmouseout event
			if (btn.onmouseout && btn.onmouseout.toString().indexOf("vbnImgSwap") != -1) {
				// Make onclick call the onmouseout event handler
				btn.onclick = function onclick() { this.onmouseout(); return true; };
			}
		}
	}
}


function vbnOverlayMouseDownBtn(e) {
	// Get the menu id
	var menuId = vbnGetOverlayMenuId(this);
	vbnOverlayClickedId = menuId;
	return true;
}


function vbnOverlayMouseDownMenu(e) {
	// Get the menu id
	vbnOverlayClickedId = this.id;
	return true;
}


function vbnOverlayMouseDownBody(e) {
	// Close the open overlay menu, unless the mouse is inside the menu
	// or the menu button.
	if (vbnOverlayOpenId != vbnOverlayClickedId) {
		vbnHideOverlay(vbnOverlayOpenId);
	}
	vbnOverlayClickedId = "";
	return true;
}
/* end styled overlay menus
=========================================================================== */
