//
// B14 Flash JS Tools V1.2
//

/**
 * This function returns the size of the window view.
 */
function getViewportSize() { 
	var height_window = $(window).height();
	var width_window = $(window).width();
	
	var size = [0, 0];
	size = [width_window, height_window];
	
	return size;
}

/**
 * Adjust the width and height of the div containing the site application.
 */
function windowResize() {
	// Get the div contaning the application swf object.
	var el = $("#flashcontent");
	
	// Calculate size of the window view
	var size = getViewportSize();
	
	// Calculate the size to adjust to
	var width = size[0] < minWidth ? minWidth+"px" : "100%";
	var height = size[1] < minHeight ? minHeight+"px" : "100%";
	
	// Set css properties for the application div
	el.css("width", width);
	el.css("height", height);
}

/**
 * Navigation from flash back or forward buttons.
 */
function b14CmsHistoryGo(offset) {
	history.go(-1);	
}

/**
 * Dynamic sizechange from flash.
 */
function changeDivSize(width, height) {
	var flashDiv = $("#flashcontent");
	var flashSite = $("#flashSite");

	var size = getViewportSize();
	height = parseInt(height)
	var newFlashWidth = parseInt(width);
	var newFlashHeight = (height > size[1]) ? height : size[1];
	
	// update site's "global minimum height"
	if (minHeight && minHeight < newFlashHeight)
		minHeight = newFlashHeight;
	
	if (newFlashWidth != 0)
		flashDiv.css("width", newFlashWidth + "px");
	
	if (newFlashHeight != 0) {
		flashDiv.css("height", newFlashHeight + "px");
		// Handle old MSIE buggy CSS engine
		if ( navigator.appName == "Microsoft Internet Explorer" && parseFloat(navigator.appVersion) < 7 )
			flashSite.css("height", newFlashHeight + "px");
	}
}

/**
 * Set scroll position to the window top.
 */
function scrollToTop() {
	$(window).scrollTo(0, 0);  // move to top of browser window
}

/**
 * Initiate b14 debug frame.
 */
function b14trace(msg) {
	var traceDiv = $("#b14TraceDivOutput");	
	var traceDivContent = $("#b14TraceDivOutputContent");	
	
	var p = document.createElement("p");
	var textNode = $(document.createTextNode(msg)).appendTo(p);
	
	traceDivContent.append(p);
	traceDiv.scrollTop(traceDivContent.height());
}

/**
 * Clear the b14 debug frame
 */
function b14traceClear() {
	var traceDivContent = $("#b14TraceDivOutputContent");
	traceDivContent.empty();
}

/**
 * Scroll function.
 */
function scrollMacBrowser(deltaX, deltaY) {
	window.scrollBy( (deltaX*-4), (deltaY*-4) );
}

/**
 * This is the universal b14 event tracking proxy.
 */
function trackEvent(category,action,label,value) {
	if (isFinite(value))
		pageTracker._trackEvent(category,action,label,value);
	else 
		pageTracker._trackEvent(category,action,label);

}

/**
 * This is the universal b14 event tracking proxy.
 */
function trackPage(name) {
	pageTracker._trackPageview(name);
}

/**
 * Get the swf adress id.
 */
function getSWFAddressID() {
	var pathString = SWFAddress.getPath();
	var allParts = pathString.split("/");
	for (var i = 0; i < allParts.length; i++) {
		if (  isFinite( parseInt(allParts[i]) )  )
			return allParts[i];
	}
	return 0;
}