//initialize here
YAHOO.util.Event.onDOMReady(init); 

var swfName = "mymovie";
var swfContainerID = "swfObj";

/**
* initialization
*
*/
function init() { 
	//add onScroll and onResize event
	YAHOO.util.Event.addListener(window, "scroll", _scrollHandler, this); 
	YAHOO.util.Event.addListener(window, "resize", _resizeHandler, this); 
	
	var so = new SWFObject("stylebook.swf", "mymovie", "100%", "100%", "8", "#ffffff");
	so.addParam('menu', 'false');    
	so.write("swfObj");
} 


/*
---------------------------------------------------------------
Basic API
---------------------------------------------------------------
*/


/**
	open window and make it front
	on safari, when popuup block is enabled it doesnt works
*/
function openWindow(url,target,toTop)
{
	window.open(url,target);
	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);
	
	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()}
}

/*
*	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());
}



