
$j = jQuery.noConflict();

$ = $j;

$j(document).ready(function(){
	
			window.onscroll = scroll_ev;
			window.onresize = scroll_ev;

			if (navigator.appName.indexOf("Explorer") != -1) {
				$j("#bottom").css({position:'absolute'});
				$j("#bottom").css({bottom:-1});
				scroll_ev();
			}
			
			//alert(history.length);
			//$('#backlink').hide();
			
			MM_preloadImages('/images/lev1_bg_over.jpg','/images/lev2_bg_over.jpg','/images/lev1_main_bg.jpg','/images/lev2_bg.jpg');
	
	// disable old events
	/*
	$j('li.Level0Item > ol').hide();

	$j('li.Level0Item').mouseover(function(){
		console.log('hover');
		$j('> ol', this).slideDown();
	}).mouseout(function(){
		$j('> ol', this).slideUp();
	});
	*/
	/*
	if (TransMenu.isSupported())
	{
		function init_transmenu_subitems(transmenu, subitems)
		{
			subitems.each(function(i){
				var link = $j('> a', this);
				var item = transmenu.addItem(link.text(), link.attr('href'), link.attr('target'));

				var subitems = $j('> ol > li', this);
				if (subitems.length)
				{
					var subtransmenu = transmenu.addMenu(transmenu.items[i], i);
					init_transmenu_subitems(subtransmenu, subitems);
				}
			});
		}

		function hide_transmenu()
		{
			TransMenuSet.registry[0].hide();
		}

		var menuitems = $j('li.Level0Item').add('li.TopMenuItem').add('#MoilHeader');

		var ms = new TransMenuSet(TransMenu.direction.down, 1, 24, TransMenu.reference.topLeft);

		// generate transmenu from html
		menuitems.each(function(){
			var subitems = $j('> ol > li', this);
			if (!subitems.length)
			{
				this.onmouseover = hide_transmenu;
			}
			else
			{
				var link = $j('> a', this);
				var transmenu = ms.addMenu(link[0], 0);

				init_transmenu_subitems(transmenu, subitems);
			}
		});

		// remove menu from html
		menuitems.find('> ol').remove();


		// init transmenu
        var aMenuHtml = [];
        for (var i = 0, menu = null; menu = TransMenu.registry[i]; i++) {
                aMenuHtml[i] = menu.toString();
        }
        $j('body').append(aMenuHtml.join(""));

		TransMenu.initialize();
	}
	*/
	
	/*20101109 removed ... no flash needed any more
	var w=746, h=180;

	var so = new SWFObject("/flash/360ansicht.swf", "homeflash", w, h, "7", "#FFFFFF");
	//alert(so);
	so.addParam("scale", "noscale");
	so.addParam("wmode", "transparent");
	so.addVariable("sw", w);
	so.addVariable("sh", h);
	so.addVariable("iu", escape('/resize/?image=roundshots/shot08.jpg&height='+h));
  if (document.getElementById("homeflash"))
		so.write("homeflash");
	//document.getElementById("homeflash").innerHTML=so;
  */
  /*
  console.log($('a.image-popup').length);
  
  $("a.lightbox1").lightBox();
 */
  
  if($j("a.image-popup").length>0) {
	  var data = {};
	  $('a.image-popup').each(function() {
		  data[$(this).attr("my_class")] = 1;
	  });
	  
	  for(var my_class in data) {
		  $j("a."+my_class).lightBox();
	  }
  }
  
  //$(document).pngFix();
  
});

		function scroll_ev(ev) {
			ev = window.event;
			pos = document.body.clientHeight-35+document.body.scrollTop;
			
			//alert(document.documentElement.scrollTop);
			if (document.documentElement.scrollTop) pos += document.documentElement.scrollTop;

			if (navigator.appName.indexOf("Explorer") == -1)
				return;
				
			$j("#bottom").css({position:'absolute'});
			$j("#bottom").css({top:pos+'px'});
			
		}

	function show_geschichte() {
					var show = function(hash) {
						hash.w.show(500, function() {
				
						});
					};
					var hide = function(hash) {
						hash.o.remove();
						hash.w.hide(500, function() {
							hash.w.empty();
						});
					};		
					
					html = "";
					
					var top = $j(window).height()-569;
					top = top/2;
					if(top<0)
						top=0;
					
					if (!$('#PopupGeschichte').length)
						$('body').prepend('<div id="PopupGeschichte" class="jqmWindow" style="top: '+top+'px; border: 1px solid white; background-color:white; text-align:center;"></div>');
					
				
					$('#PopupGeschichte').html('<iframe src="geschichte.php" height="569" width="822" frameborder="0"></iframe>');
					
					//$.modal($('#PopupGeschichte'));
					$("#PopupGeschichte").jqm({modal: false, onShow: show, onHide: hide}).jqmShow();	
					//window.open('geschichte.php','test','width=822,height=569');
		} 
		function hide_geschichte() 
		{
			$("#PopupGeschichte").jqmHide();
		}


		
		function go_katalog(params)
		{
			if (params)
				params = '?' + $.param(params);
			else
				params = '';
			
			var opts, url;
		
			opts = 'width=1014,height=740,resize=no,scrollbars=no';
		
			url = 'http://www.fliesenkatalog.eu/katalog/katalog.php'+params;
		
		
			last_window = wnd = window.open(url, 'fliesenkatalog_popup',opts);
			if (!wnd)
			{
				alert('Bitte aktivieren Sie javascript popups!');
			}
			else
				wnd.focus();
		}
				
		function MM_preloadImages() { //v3.0
		  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
		}
		
function showKatalog_old() {	
	var correct_flash_version = (deconcept.SWFObjectUtil.getPlayerVersion().major >= 7);
	
	var show = function(hash) {
			hash.w.fadeIn();
	}
	
	var hide = function(hash) {
		hash.o.remove();
		hash.w.fadeOut();
	}
	
	if (!$j("#PopupGala").length) {
		if(!correct_flash_version)
			$j('body').prepend('<div id="PopupGala" style="position: absolute; width:800px; height:530px; border: 1px solid white; margin-left: -400px; top: 2%" class="jqmWindow"><div style="border: 1px solid black; background: white; padding: 20px; width: 320px; position: absolute; top: 170px; left: 100px;">Diese Seite ben&ouml;tigt Flash-Player mindestens Version 7<br>und aktiviertes Javascript!<br /><br /><a target="_blank" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BUIGP">Klicken Sie hier um Adobe Flash Player zu installieren</a></div></div>');
		else
			$j('body').prepend('<div id="PopupGala" style="position: absolute; width:800px; height:545px; background-color:white; border: 1px solid white; margin-left: -400px; top:2%;" class="jqmWindow"><iframe src="/gala/index2.html" height="530" width="800" frameborder="0" framespacing="0" srollbars="0"></iframe></div>');
	}
	
	$j("#PopupGala").jqm({modal: false,onShow: show, onHide: hide}).jqmShow();
}

function showKatalog(path) {	
	var correct_flash_version = (deconcept.SWFObjectUtil.getPlayerVersion().major >= 7);
	
	var show = function(hash) {
			hash.w.fadeIn();
	}
	
	var hide = function(hash) {
		hash.o.remove();
		hash.w.fadeOut();
	}
	
	if (path == undefined)
		path = "";
	
	if (!$j("#PopupGala").length) {
		if(!correct_flash_version)
			$j('body').prepend('<div id="PopupGala" style="position: absolute; width:800px; height:530px; border: 0px solid white; margin-left: -400px; top: 2%;" class="jqmWindow"><div style="border: 1px solid black; background: white; padding: 20px; width: 320px; position: absolute; top: 170px; left: 100px;">Diese Seite ben&ouml;tigt Flash-Player mindestens Version 7<br>und aktiviertes Javascript!<br /><br /><a target="_blank" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BUIGP">Klicken Sie hier um Adobe Flash Player zu installieren</a></div></div>');
		else
			$j('body').prepend('<div id="PopupGala" style="position: absolute; width:800px; height:545px; background-color:white; border: 0px solid white; margin-left: -400px; top:2%; background: url(/images/galakatalog/auswahl_aufloesung.jpg) bottom center no-repeat; background-color: white;" class="jqmWindow"><div id="auswahlLogo"></div><div style="text-align: right; margin-right: 8px; margin-top: 8px;"><a href="javascript: parent.hideKatalog();"><img src="/images/close.jpg" border="0"/></a></div><div id="aufloesungAuswahl"><a href="javascript:fillKatalog(1024,768,\''+path+'\');" id="aufl1"><span style="display: block;">&nbsp;</span></a><a href="javascript:fillKatalog(1280,1024,\''+path+'\');" id="aufl2"><span style="display: block;">&nbsp;</span></a><a href="javascript:fillKatalog(1440,1050,\''+path+'\');" id="aufl3"><span style="display: block;">&nbsp;</span></a><a href="javascript:fillKatalog(1024,768,\''+path+'\');" id="stdAuswahl"><span style="display: block;">&nbsp;</span></a></div></div>');
	}
	
	$j("#PopupGala").jqm({modal: false,onShow: show, onHide: hide}).jqmShow();
}

function fillKatalog(width,height,path) {
	
	var width_iframe = 800;
	var height_iframe = 530;
	
	$j("#PopupGala").css({"background": "none","background-color": "white"});
	
	if(width==1280) {
		width_iframe = 1056;
		height_iframe = 801;
		$j("#PopupGala").css({"width":width_iframe+"px","height": height_iframe+"px","margin-left": "-528px"});
	}else if(width==1440) {
		width_iframe = 1216;
		height_iframe = 827;
		$j("#PopupGala").css({"width":width_iframe+"px","height": height_iframe+"px","margin-left": "-608px"});
	}
	
	if (!path)
		path = "/katalog";
	
	
	//gala/index2
	$j("#PopupGala").html('<iframe src="'+path+'/?width='+width_iframe+'&height='+height_iframe+'" height="'+height_iframe+'" width="'+width_iframe+'" frameborder="0" framespacing="0" srollbars="0"></iframe>');
}

function hideKatalog()
{
	$j("#PopupGala").jqmHide();
}

function openCBergmannVideo() {
	openVideoDetail("CBergmann",686,428);
}

function openVideoDetail(video_name, width, height) {
	var correct_flash_version = (deconcept.SWFObjectUtil.getPlayerVersion().major >= 7);
	
	var show = function(hash) {
			hash.w.fadeIn();
	}
	
	var hide = function(hash) {
		hash.o.remove();
		hash.w.fadeOut();
		$j("#VideoContainer").remove();
		$j("#PopupGala").remove();
	}
	
	
	
	if (!$j("#PopupGala").length) {
		if(!correct_flash_version)
			$j('body').append('<div id="PopupGala" style="position: absolute; left: 50%; width:'+width+'px; height:'+(height+28)+'px; border: 0px solid white; margin-left: -'+(width/2)+'px; top: 50%; margin-top: -'+(height/2)+'px;" class="jqmWindow"><div style="border: 1px solid black; background: white; padding: 20px; width: 320px; position: absolute; top: 170px; left: 100px;">Diese Seite ben&ouml;tigt Flash-Player mindestens Version 7<br>und aktiviertes Javascript!<br /><br /><a target="_blank" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BUIGP">Klicken Sie hier um Adobe Flash Player zu installieren</a></div></div>');
		else
			$j('body').append('<div id="PopupGala" style="position: absolute; left: 50%; width:'+width+'px; height:'+(height+35)+'px; background-color:white; border: 0px solid white; margin-left: -'+(width/2)+'px; top: 50%; margin-top: -'+(height/2)+'px; background-color: white;" class="jqmWindow"><div style="text-align: right; margin: 8px;"><a href="javascript: parent.hideVideo();"><img src="/images/close.jpg" border="0"/></a></div><div id=\"VideoContainer\" style=\"width: '+(width)+'px; height: '+(height)+'px;\"></div></div>');
	}
	var et_key			= "Xyxa23";
	var et_pagename	= '150 Jahre C. Bergmann - der Film';
	et_eC_Wrapper(et_key,decodeURIComponent(et_pagename),decodeURIComponent(et_pagename));
	
	var so = new SWFObject("/videos/"+video_name+".swf?q="+(Math.random()*1000000), "video_popup", width, height, "1", "#ffffff");
	so.addParam('wmode', 'transparent');
	so.addParam('scale','default');
	so.addParam('quality','high');
	so.write("VideoContainer");
	
	$j("#PopupGala").jqm({modal: false,onShow: show, onHide: hide}).jqmShow();
}

function openVideo(video_name) {
	var correct_flash_version = (deconcept.SWFObjectUtil.getPlayerVersion().major >= 7);
	
	var show = function(hash) {
			hash.w.fadeIn();
	}
	
	var hide = function(hash) {
		hash.o.remove();
		hash.w.fadeOut();
		$j("#VideoContainer").remove();
		$j("#PopupGala").remove();
	}
	
	
	
	if (!$j("#PopupGala").length) {
		if(!correct_flash_version)
			$j('body').prepend('<div id="PopupGala" style="position: absolute; width:550px; height:450px; border: 0px solid white; margin-left: -275px; top: 2%;" class="jqmWindow"><div style="border: 1px solid black; background: white; padding: 20px; width: 320px; position: absolute; top: 170px; left: 100px;">Diese Seite ben&ouml;tigt Flash-Player mindestens Version 7<br>und aktiviertes Javascript!<br /><br /><a target="_blank" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BUIGP">Klicken Sie hier um Adobe Flash Player zu installieren</a></div></div>');
		else
			$j('body').prepend('<div id="PopupGala" style="position: absolute; width:550px; height:450px; background-color:white; border: 0px solid white; margin-left: -275px; top:2%; background-color: white;" class="jqmWindow"><div style="text-align: right; margin-right: 8px; margin-top: 8px;"><a href="javascript: parent.hideVideo();"><img src="/images/close.jpg" border="0"/></a></div><div id=\"VideoContainer\" style=\"width: 550px; height: 400px;\"></div></div>');
	}
	
	var so = new SWFObject("/videos/"+video_name+".swf?q="+(Math.random()*1000000), "video_popup", "550", "420", "1", "#ffffff");
	so.addParam('wmode', 'transparent');
	so.addParam('scale','default');
	so.addParam('quality','high');
	so.write("VideoContainer");
	
	$j("#PopupGala").jqm({modal: false,onShow: show, onHide: hide}).jqmShow();
}

function hideVideo() {
	$j("#PopupGala").jqmHide();
}

function imagePreview(){
    /* CONFIG */
          
          xOffset = 10;
          yOffset = 30;
          
          // these 2 variable determine popup's distance from the cursor
          // you might want to adjust to get the right result
    /* END CONFIG */
          
    $j("a.preview").hover(function(e){
          $j("body").append("<div id='preview'><img src='"+ this.name + "' border='0'></div>");                                               
          $j("#preview")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px")
                .fadeIn("fast");                               
  },
    function(){ 
          $j("#preview").remove();
  });     
    $j("a.preview").mousemove(function(e){
          $j("#preview")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px");
    });               
}
