function getObj(name) {
	if (document.getElementById) {
		return document.getElementById(name);
	} else if (document.all) {
		return document.all[name];
	}
}

function closePopup() {
	
	var newsyearList = document.getElementById("ctl00_mainContent_NewsList_NewsYearDropDown");
    if(newsyearList != undefined)
        newsyearList.style.visibility = 'visible';
    
	getObj("flashcontent").style.width = "0%";
	getObj("flashcontent").style.height = "0%";
	
	delete window.onresize;
	delete window.onscroll;
}

function closeMapPopup()
{
    //Show the select component if they were hidden (IE6)
	var countryList = document.getElementById("ctl00_mainContent_ddlCountry");
    var cityList = document.getElementById("ctl00_mainContent_ddlCity");
    if(cityList != undefined)
    {
        countryList.style.visibility = 'visible';
	    cityList.style.visibility = 'visible';
    }
    getObj("flashcontent").style.width = "0%";
	getObj("flashcontent").style.height = "0%";
	
	delete window.onresize;
	delete window.onscroll;
}

function getSwf(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}

function getYOffset() {       
	var yPos = 0;
	if (window.innerHeight) {
		yPos = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		yPos = document.documentElement.scrollTop;
	} else if (document.body) {
		yPos = document.body.scrollTop;
	}
	return yPos;
}

function updateSize() {
	var popupDiv = getObj("flashcontent");
	var cHeight = 0;
	var cWidth = 0;
	if (window.innerWidth) {
		cWidth = window.innerWidth;
		cHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		cWidth = document.documentElement.clientWidth;
		cHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		cWidth = document.body.clientWidth;
		cHeight = document.body.clientHeight;
	}
	
	popupDiv.style.top = getYOffset()+"px";
	popupDiv.style.width = cWidth - (cWidth-860)/2+"px";
	popupDiv.style.height = cHeight+"px";
	$("#flashcontent").css("left",(cWidth-900)/2 + "px");
}
function initSlider()
{
    $('#lastViewedItemContainer').serialScroll({
		target:'#lastViewedItems',
		items:'div.floorItem', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'img.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'img.next',// Selector to the 'next' button (absolute too)
		axis:'y',// The default is 'y' scroll on both ways
		duration:400,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		cycle:false,// Cycle endlessly ( constant velocity, true is the default )
		//queue:false,// We scroll on both axes, scroll both at the same time.
		//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
		//stop:false,// Each click will stop any previous animations of the target. (false by default)
		//lock:true, // Ignore events if already animating (true by default)		
		//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
		//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
		//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		//interval:1000, // It's the number of milliseconds to automatically go to the next
		//constant:true, // constant speed
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});

}

function showPopup(xmlPath, rootPath, floorid, articleNumber, languageCode, page, systemFonts) {

	$.get("/Ajax/LastViewedItems.aspx?floorId=" + floorid + "&languageCode=" + languageCode, function(response) {
	        
	        $("#lastViewedItemContainer").show();
            $("#lastViewedItemsHolder").html(response).show();
            $("#lastViewedItemsFooter").show();
            
            initSlider();
            showPopUpFlash(xmlPath, rootPath, articleNumber, languageCode, page, systemFonts);
    });
}

function showPopUpFlash(xmlPath, rootPath, articleNumber, languageCode, page, systemFonts)
{
    updateSize(); 
	if(so) so = null;

	var so = new SWFObject(xmlPath+"floorsPopup.swf", "flashPopup", "100%", "100%", "9", "#FFFFFF");
	var xmlString = rootPath + "LoadProductXml.aspx?articleNumber="+articleNumber + "%26epslanguage="+languageCode;

	so.addParam("wmode", "transparent");
	so.addVariable("xml", xmlString);
	so.addVariable("lang", languageCode);
	so.addVariable("font", xmlPath + "fonts/");
	so.addVariable("page", page);
	so.addVariable("systemfonts", systemFonts);
	so.write("flashcontent");
	
	if(document.forms[0]) window.flashPopup = document.forms[0].flashPopup;
    //  updateSize();
	window.onscroll = updateSize;
	window.onresize = updateSize;
	var popupDiv = getObj("flashcontent");
	var cHeight = 0;
	var cWidth = 0;
	if (window.innerWidth) {
		cWidth = window.innerWidth;
		cHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		cWidth = document.documentElement.clientWidth;
		cHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		cWidth = document.body.clientWidth;
		cHeight = document.body.clientHeight;
	}
    $("#flashcontent").css("left",(cWidth-900)/2 + "px");
}


function showPopupNews(xmlPath, xmlUrlEncodedString, languageCode) {
	
	updateSize();
	
	if(so) so = null;
	                                                                                                                      
	var so = new SWFObject(xmlPath+"floorsPopup.swf", "flashPopup", "100%", "100%", "9", "#FFFFFF");
	
	so.addParam("wmode", "transparent");
	so.addVariable("xmlContent", xmlUrlEncodedString);
	so.addVariable("lang", languageCode);
	so.addVariable("font", xmlPath + "fonts/");
	so.addVariable("page", "news");
	so.write("flashcontent");
	
	if(document.forms[0]) window.flashPopup = document.forms[0].flashPopup;
	
	window.onscroll = updateSize;
	window.onresize = updateSize;

    var newsyearList = document.getElementById("ctl00_mainContent_NewsList_NewsYearDropDown");
    newsyearList.style.visibility = 'hidden';                                                                                               
}

function showinfoPopup(xmlPath, languageCode, pageLink) {
	
    $.get("/Ajax/LoadInfoPopupXml.aspx", { lang: languageCode, pageLink: pageLink }, function(data) {
	    updateSize();
    	
	    if(so) so = null;
    	                                                                                                                                                    
	    var so = new SWFObject(xmlPath + "infoPopup.swf", "flashPopup", "100%", "100%", "9", "#FFFFFF");
	    so.addParam("wmode", "transparent");
        so.addVariable("xmlContent", data);
        so.addVariable("font", xmlPath + "fonts/");
        so.addVariable("lang", languageCode);
        so.write("flashcontent");

	    if(document.forms[0]) window.flashPopup = document.forms[0].flashPopup;
    	
	    window.onscroll = updateSize;
	    window.onresize = updateSize;
            
    });

}


function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

