//initialize here
YAHOO.util.Event.onDOMReady(init); 

var swfName = "nn";
var swfContainerID = "flashcontent";

/**
* initialization
*
*/
function init() { 
	//add onScroll and onResize event
	YAHOO.util.Event.addListener(window, "scroll", _scrollHandler, this); 
	YAHOO.util.Event.addListener(window, "resize", _resizeHandler, this); 
} 


/*
---------------------------------------------------------------
Basic API
---------------------------------------------------------------
*/


/**
	open window and make it front
	on safari, when popuup block is enabled it doesnt works
*/
function openWindow(url,target,toTop)
{
	var w = window.open( url, target );
	if(toTop==true)
		w.focus();
}

/**
* set swf's size
*/
function setStageSize( width, height, resetPosition )
{
	width = Math.max(width, YAHOO.util.Dom.getViewportWidth());
	height = Math.max(height, YAHOO.util.Dom.getViewportHeight());
	
	var div = YAHOO.util.Dom.get(swfContainerID);
	YAHOO.util.Dom.setStyle(div, "width", width);
	YAHOO.util.Dom.setStyle(div, "height", height);
	
	if(resetPosition==true)
		window.scroll(0,0);
}

/**
* set swf's size
*/
function setStageHeight( height, resetPosition )
{
	
	height = Math.max(height, YAHOO.util.Dom.getViewportHeight());
	
	var div = YAHOO.util.Dom.get(swfContainerID);
	YAHOO.util.Dom.setStyle(div, "height", height);
	YAHOO.util.Dom.setStyle(swfName, "height", height);
	
	if(resetPosition==true)
		window.scroll(0,0);
}

/**
*	returns viewport's x, y, width and height
*/
function getViewportRect()
{
	var scrl = getScroll();
	return {
		x: scrl.x,
		y: scrl.y,
		width: YAHOO.util.Dom.getViewportWidth(), 
		height: YAHOO.util.Dom.getViewportHeight()}
}

function getDocumentHeight() {
	return document.height;
}

function getDocumentWidth() {
	return document.width;
}



/*
*	return viewpots x and y
*/
function getScroll()
{
	return {
		x: document.body.scrollLeft || document.documentElement.scrollLeft,
		y: document.body.scrollTop  || document.documentElement.scrollTop
	}
}

// get swf
function getSWF(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}


/*
---------------------------------------------------------------
EventHandlers
---------------------------------------------------------------
*/
//called when resized
function _scrollHandler()
{
	getSWF(swfName).setScroll(getScroll());
}

//called when scrolled
function _resizeHandler()
{
	getSWF(swfName).setViewportRect(getViewportRect());
}





// ==================
// = Wheel Controll =
// ==================
var isPreventingWheel = false;
function mouseWheelListener(event) {
	if(isPreventingWheel && !macSafari) {
		preventWheel(event);
	}
}
function preventWheel(event) {
	if(!event) {
		event = window.event;
	}
	
	var delta = 0;
	
	if(event.wheelDelta) {
		delta = event.wheelDelta / 120;
		if(window.opera) {
			delta = -delta;
		}
	} else if(event.detail) {
		delta = -event.detail / 3;
	}
	
	getSWF(swfName).wheelDelta(delta);
	
	if(event.preventDefault) {
		event.preventDefault();
	}
	event.returnValue = false;
}
function disableWheelScroll() {
	isPreventingWheel = true;
}
function enableWheelScroll() {
	isPreventingWheel = false;
}
if(window.addEventListener) {
	window.addEventListener('DOMMouseScroll', mouseWheelListener, false);
}
window.onmousewheel = document.onmousewheel = mouseWheelListener;

var uaString  = navigator.userAgent.toUpperCase();
var macSafari = uaString.indexOf("SAFARI") != -1 && uaString.indexOf("MAC OS X") != -1;


// =============
// = Scrolling =
// =============
function scrollToTop(duration) {
	(new YAHOO.util.Scroll(document.body, {scroll:{to:[0, 0]}}, duration, YAHOO.util.Easing.easeOutStrong)).animate();
}

function scrollToPos(pos) {
	(new YAHOO.util.Scroll(document.body, {scroll:{to:[0, pos]}}, 1, YAHOO.util.Easing.easeOutStrong)).animate();
}

