//initialize here
YAHOO.util.Event.onDOMReady(init); 

var swfName = "juniors_trend";
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);
}

/**
* set swf's size
*/
function setStageHeight( height ){
	document.getElementById("flashcontent").style.height = height + "px"; 
	document.getElementById("juniors_trend").style.height = height + "px";
	window.setTimeout(window.parent.updateFlashNav,200);
}
function updateFlashNav(){
	getSWF(swfName).updateNav();
}
/**
*	returns viewport's x, y, width and height
*/
function getViewportRect(){
	var scrl = getScroll();
	return {
		y: scrl.y,
		height: YAHOO.util.Dom.getViewportHeight(),
		offset: YAHOO.util.Dom.getY(swfContainerID)}		
}

/*
*	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 {
      if(document[movieName].length != undefined){
          return document[movieName][1];
      }
        return document[movieName];
    }
}

function flashAlert(value){
	alert(value);
}

//called when resized
function _scrollHandler(){
	getSWF(swfName).setScroll(getScroll());
}

//called when scrolled
function _resizeHandler(){
	getSWF(swfName).setViewportRect(getViewportRect());
}
