/*
 * Javascript Functions
 *
 * Copyright (c) CLICKSPORTS
 * $Rev$
 * $Author$
 * $Date$
 *
 */

// Load some required stuff before page renders.
document.observe('dom:loaded', function() {
	new subnav('subnavigation');
	if($('teaser')) swfobject.embedSWF("layout/flash/picturefader_small.swf", "swf_content_teaser", "216", "136", "9.0.0", "layout/flash/expressInstall.swf", '', { flashVars: fvars, wmode: 'opaque' });
});

/**
 * Gets and sets subnavigation arrows
 * @param String id
 */
var subnav = Class.create({
	
	initialize: function(navElm) {
		
		this.navElm = $(navElm);
		this.activeLink = $('subnavigation_active')
		
		if (this.navElm !== null && this.activeLink !== null) {
			this.lis = this.navElm.select('li');
			this.setEvtListeners();
		}
	},
	
	setEvtListeners: function() {
		this.lis.each(function(li) {
			if (li.readAttribute('id') != 'subnavigation_active') {
				li.observe('mouseover', function(e) { this.activeLink.addClassName('noarrow'); }.bindAsEventListener(this));
				li.observe('mouseout', function(e) { this.activeLink.removeClassName('noarrow'); }.bindAsEventListener(this));
			}
		}.bind(this))
	}
	
});

// Functions to show a flashobject
var ShowFlashObject = Class.create({
	
	initialize: function(elm, fwidth, fheight, language, headline) {

		this.headline = headline;
		this.lang = language;
		this.fwidth = fwidth;
		this.fheight = fheight;

		this.elm = $(elm);
		
		this.initializeDom();
		this.hideAllNeeded();

		this.addEvents();
		this.buildHTML();
		
	},
	
	initializeDom: function() {
		
		this.panorama_link = this.elm.down('a.panorama_link');
		this.panorama_sub = this.elm.down('div.panorama_right');
		this.panorama_desc = this.elm.down('div.panorama_description');
		this.player = this.elm.down('div.panorama_inset');
		
		this.flashfile = this.panorama_link.getAttribute('rel');
		
	},
	
	hideAllNeeded: function() {
		this.panorama_desc.hide();
		this.player.hide();
	},
	
	addEvents: function() {
		
		Event.observe(this.panorama_link, 'click', function(e) {

			Event.stop(e);
			this.show();

		}.bindAsEventListener(this));
		
		Event.observe(this.panorama_sub, 'click', function(e) {

			Event.stop(e);
			this.show();

		}.bindAsEventListener(this));
		
	},
	
	show: function() { this.player.show(); $('footer').hide(); },
	hide: function() { this.player.hide(); $('footer').show(); },
	
	buildHTML: function() {
		
		bd = $('teaser');
		
		if (bd==null) bd = $('main');
		
		sf_width = bd.getWidth();
		sf_height = bd.getHeight();
		
		this.player.update(
			'<div class="showflash" style="width: ' + sf_width + 'px; height: ' + sf_height + 'px;"><div class="showflash_inset">' +
			'<div class="flashoverview"><div class="flashpanorama">' +
			'<div class="flashheading">' + this.getHeadline() + '</div>' +
			'<div class="flashclose">' + this.getCloseImage() + '</div>' +
			'<div class="flashmovie">' +
			'<object width="' + this.fwidth + '" height="' + this.fheight + '" type="application/x-shockwave-Flash"  data="' + this.flashfile + '"  >' +
			'	<param name="movie" value="' + this.flashfile + '" />' +
			'	<param name="quality" value="high" />' +
			'	<param name="wmode" value="opaque" />' +
			'	<param name="bgcolor" value="#FFFFFF" />' +
			'</object>' +
			'</div>' +
			'<div class="flash_description">' + this.panorama_desc.innerHTML + '</div>' +
			'</div></div>' +
			'</div></div>'
			
		);
		
		// Update the settings
		this.player.down('div.showflash_inset').setStyle({
			'width': (this.fwidth + 2) + 'px',
			'top': (this.fheight/2)-80 + 'px'
		});
		
		Event.observe(this.player.down('div.showflash'), 'click', function(e) {
			evt = Event.element(e);
			if(evt.hasClassName('showflash')) this.hide();
		}.bindAsEventListener(this))
		
		Event.observe(this.player.down('img.flash_closeimg'), 'click', function(e) {
			this.hide();
		}.bindAsEventListener(this))
		
	},
	
	getCloseImage: function() {
		
		if(this.lang == 'de') this.closeImage = 'files/panorama_close_de.jpg';
		else this.closeImage = 'files/panorama_close_en.jpg';
		
		return '<img src="' + this.closeImage + '" alt="" class="flash_closeimg" />';
		
	},
	
	getHeadline: function() {
		
		return '<img src="files/rcontent_bg.gif" alt="" style="bottom: 3px; position: relative;" /><img src="' + this.headline + '" alt="' + this.panorama_link.innerHTML + '" />';
		
	}
});

/******************************************
 * Schlemmer SPECIFIC
******************************************/
function show_qt(panorama_id, lageplan, teaser, qt_movie, set_visible, lang) {

	qt_movie_wrapper = "panorama_view_" + panorama_id;
	hotspot_container = $("panorama_right_" + panorama_id);

	// Set language translations
	if( typeof(lang) == "undefined" || lang == "0") {
		headline = '<img src="files/panorama_heading_de.jpg" alt="Virtueller Messestand" style="margin-bottom: 10px; float: left;" />';
		content2_content = "Um sich frei im Raum zu bewegen halten Sie die linke Maustaste gedrückt und ziehen Sie den Zeiger in die gewünschte Richtung. Weiterführende Informationen zu unseren Produkten erhalten Sie über klickbare Bereiche im virtuellen Messestand.";
		navigation_close_element = '<img src="files/panorama_close_de.jpg" alt="Schliessen" />';
	} else if (lang == "1") {
		headline = '<img src="files/panorama_heading_en.jpg" alt="Virtual stand" style="margin-bottom: 10px; float: left;" />';
		content2_content = "Just doubleclick the respective products or subject areas. To navigate within the booth/stand hold the left mousekey and move in any direction.";
		navigation_close_element = '<img src="files/panorama_close_en.jpg" alt="Close" />';
	}

	if($(qt_movie_wrapper)) {

		element=$(qt_movie_wrapper);

		// Check if user uses Safari
		isSafari3 = false;
		if(window.devicePixelRatio) {
			panorama_player_style = "margin-top: 10px; top: 0px;";
		} else {
			panorama_player_style = "";
		}


		bd = $('teaser');
		sf_width = bd.getWidth();
		sf_height = bd.getHeight();

		element.setStyle({
			width: sf_width + 'px',
			height: sf_height + 'px'
		});

		// Check if our qt-movie is visible	
		if(element.className=="panorama_view" || element.className=="" || set_visible) {

			// Scroll to top
			$('teaser').scrollTo();

			// Get generated headline-image
			eval("headline_img = headline_src_" + panorama_id);

			// Needed elements
			content2 = '<div class="panorama_content_wrapper"><div class="panorama_content_wrapper_left"><img src="' + headline_img + '" /><br />' + content2_content + '</div>';
			navigation_sub = '<div id="panorama_right_overview' + panorama_id + '" class="panorama_overview" style="background-image:url(' + lageplan + ');">' + $('panorama_right_overview' + panorama_id).innerHTML + '</div><div style="clear: both;"></div></div>';
			navigation_close = '<p class="panorama_navigator"><a href="javascript:close_qt(\'' + panorama_id + '\');">' + navigation_close_element + '</a></p>';

			movie = load_movie("files/" + qt_movie, panorama_id);

			//element.innerHTML = '<div class="panorama_player" style="' + panorama_player_style + '"><img src="files/headlines/headline_VirtuellerMessestand_0.png" />' + load_movie("files/" + qt_movie, panorama_id) + '<div id="panorama_right_overview' + panorama_id + '" class="panorama_overview" style="background-image:url(' + lageplan + ');">' + $('panorama_right_overview' + panorama_id).innerHTML + '</div></div>';
			element.innerHTML = '<div class="panorama_player" style="' + panorama_player_style + '">' + headline + navigation_close + movie + content2 + navigation_sub + '</div>';
			element.addClassName('video_visible');
			element.show();
			$('footer').hide();
			
			hotspot_container.style.backgroundImage='url(' + lageplan + ')';
			
		} else {
		
			element.removeClassName('video_visible');
			element.hide();
		
		}
	
	}

}

function load_movie(movie, panorama_id) {
	
	// Build the html for the movie
	//object = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="393" width="632"><param name="type" value="video/quicktime" /><param name="cache" value="true" /><param name="wmode" value="transparent" /><param name="loop" value="false" /><param name="src" value="' + movie + '" /><param name="controller" value="false" /><param name="volume" value="80%" /><param name="autoplay" value="true" /><embed pluginspage="http://www.apple.com/de/quicktime/download/" height="393" width="632" type="video/quicktime" cache="true" loop="false" src="' + movie + '" controller="false" volume="80%" autoplay="true"></object>';
	object = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="350" width="563"><param name="type" value="video/quicktime" /><param name="cache" value="true" /><param name="wmode" value="transparent" /><param name="loop" value="false" /><param name="src" value="' + movie + '" /><param name="controller" value="false" /><param name="volume" value="80%" /><param name="autoplay" value="true" /><embed pluginspage="http://www.apple.com/de/quicktime/download/" height="350" width="563" type="video/quicktime" cache="true" loop="false" src="' + movie + '" controller="false" volume="80%" autoplay="true"></object>';
	return object;
	
}

function close_qt(panorama_id) {
	
	qt_movie_wrapper = "panorama_view_" + panorama_id;
	hotspot_container = $("panorama_right_" + panorama_id);
	
	$(qt_movie_wrapper).hide();	
	$('footer').show();
}

function switch_qt(panorama_id, lageplan, teaser) {
	
	hotspot_container = $('panorama_right_' + panorama_id);
	hotspot_obj = {};
	
	if (hotspot_container.className != "panorama_right_visible" && hotspot_container.className=="panorama_right") {
	
		hotspot_container.style.backgroundImage = 'url(' + lageplan + ')';
		
		//Display Hotspots
		hotspots_src = hotspot_container.select('a.panorama_hotspot_inactive');
		
		hotspots_src.each(function(hotspot){
			hotspot.removeClassName('panorama_hotspot_inactive');
			hotspot.addClassName('panorama_hotspot_active');
		}, hotspot_obj);
	
		hotspot_container.addClassName('panorama_right_visible');
	
	}
	else {

		// Remove Hotspots
		hotspots_src = hotspot_container.select('a.panorama_hotspot_active');
		
		hotspots_src.each(function(hotspot){
			hotspot.removeClassName('panorama_hotspot_active');
			hotspot.addClassName('panorama_hotspot_inactive');
		}, hotspot_obj);

		hotspot_container.removeClassName('panorama_right_visible');
		hotspot_container.style.backgroundImage = 'url(' + teaser + ')';
	}
}

function aufklappliste (id) { $(id).toggle(); }
