
//define global hash to hold area and flyout coordinates
var timer;
var flyoutdelay = 3000; // in milliseconds
var OsBrowser;

// Flyout RecommendForm
var showFlyout = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayLayer')
	.fadeIn(fadespeed)
}

// Flyout ProductImageBig
var showFlyoutLense = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayLayerLense')
	.fadeIn(fadespeed)
}

// Flyout BeraterContact
var showFlyoutBerater = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayLayerBerater')
	.fadeIn(fadespeed)
}

// Flyout GLContact
var showFlyoutGL = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayLayerGL')
	.fadeIn(fadespeed)
}

// Flyout Discount
var showFlyoutDiscount = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayLayerDiscount')
	.fadeIn(fadespeed)
}
      

// Flyout Product
var showFlyoutProduct = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayLayerProduct')
	.fadeIn(fadespeed)
}

// Flyout Basket show
var showFlyoutBasket = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayAddedToBasket').fadeIn(fadespeed)
	$('#basket').fadeIn(fadespeed)
	$('#basketTop').fadeIn(fadespeed)
	$('#basketMain').fadeIn(fadespeed)
}

// Flyout Basket show
var showFlyoutFavorites = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayAddedToFavorites').fadeIn(fadespeed)
	$('#basket').fadeIn(fadespeed)
	$('#basketTop').fadeIn(fadespeed)
	$('#basketMain').fadeIn(fadespeed)
}

// Flyout Basket hide
var hideFlyoutBasket = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayAddedToBasket').fadeOut(fadespeed)
}

// Flyout Basket hide
var hideFlyoutFavorites = function(id,fadespeed){
	if(fadespeed==''){fadespeed = 'slow';}
	$('#overlayAddedToFavorites').fadeOut(fadespeed)
}

$(document).ready(function(){
	
	
	// fill the browser var
	
	jQuery.each(jQuery.browser, function(i, val) {
		if(i == "mozilla" && val == true) {
			OsBrowser = "mozilla";
		}
		else if(i == "msie" && val == true) {
			OsBrowser = "msie";
		}
		else if(i == "opera" && val == true) {
			OsBrowser = "opera";
		}
		else if(i == "safari" && val == true) {
			OsBrowser = "safari";
		}
		//alert(OsBrowser);
	});
	
	
	// showFlyout RecommendFrom
	$('a.showFlyout').click(function(){
		showFlyout($(this).attr('class'),'slow');
	});
	
	// close Flyout RecommendForm
	$('#overlayLayer div.closebutton').click(function(){
		$('#overlayLayer').hide();		
	});
	
	// showFlyout ProductImageBig
	$('a.showFlyoutLense').click(function(){
		showFlyoutLense($(this).attr('class'),'slow');
	});
	
	// close Flyout ProductImageBig
	$('#overlayLayerLense div.closebutton').click(function(){
		$('#overlayLayerLense').hide();	
	});
	
	// showFlyout BeraterContact
	$('a.showFlyoutBerater').click(function(){
		showFlyoutBerater($(this).attr('class'),'slow');
	});
		
	// close Flyout BeraterContact
	$('#overlayLayerBerater div.closebutton').click(function(){
		$('#overlayLayerBerater').hide();		
	});
	
	// showFlyout GLContact
	$('a.showFlyoutGL').click(function(){
		showFlyoutGL($(this).attr('class'),'slow');
	});
	
	// close Flyout GLContact
	$('#overlayLayerGL div.closebutton').click(function(){
		$('#overlayLayerGL').hide();		
	});
	
	// Get Pos of Discount Ico
    $('a.showFlyoutDiscount').click(function(){
		var browser = OsBrowser;
        var arrPos = $(this).offset();
		var addX = 20;
		var addY = 1;
		if(browser == "safari" || browser == "undefined") {
			addX = 90;
			addY = 0;
		}
		//alert("Browser: " + browser + " " +addX + " und " + addY);
		var x = arrPos.left + addX;
		var y = arrPos.top + addY
		//alert("x-position:" + x + "y-position:" + y);
		$('#overlayLayerDiscount').css({left:x, top:y})
		showFlyoutDiscount($(this).attr('class'),'slow');
		
	});
	
	// Get Pos of Basket Ico
    $('a.showFlyoutBasket').click(function(){
        var arrPos = $(this).offset();
		var x = arrPos.left - 65;
		var y = arrPos.top - 80;
		//alert("x-position:" + x + "y-position:" + y);
		$('#overlayAddedToBasket').css({left:x, top:y})
		showFlyoutBasket($(this).attr('class'),'slow');
		
		// close Flyout Basket
		if($('#overlayAddedToBasket').css('display')=='block'){
        timer = setTimeout("hideFlyoutBasket('"+$(this).attr('class')+"','slow')",flyoutdelay);
        }
	 
	});	
	
		// Get Pos of Basket Ico
    $('a.showFlyoutFavorites').click(function(){
        var arrPos = $(this).offset();
		var x = arrPos.left - 65;
		var y = arrPos.top - 80;
		//alert("x-position:" + x + "y-position:" + y);
		$('#overlayAddedToFavorites').css({left:x, top:y})
		showFlyoutFavorites($(this).attr('class'),'slow');
		
		// close Flyout Favorites
		if($('#overlayAddedToFavorites').css('display')=='block'){
        timer = setTimeout("hideFlyoutFavorites('"+$(this).attr('class')+"','slow')",flyoutdelay);
        }
	 
	});	
	
	// Get Pos of RecommendForm
    $('a.showFlyoutRecommend').click(function(){
        var arrPos = $(this).offset();
		var x = arrPos.left + 10;
		var y = arrPos.bottom;
		//alert("x-position:" + x + "y-position:" + y);
		$('#overlayLayerProduct').css({left:x, top:y})
		showFlyoutProduct($(this).attr('class'),'slow');
		
	});

	
	// close Flyout Discount
	$('#overlayLayerDiscount div.closebutton').click(function(){
		$('#overlayLayerDiscount').hide();
	});	
	
	
	
	// showFlyout Product
	$('a.showFlyoutProduct').click(function(){
		showFlyoutProduct($(this).attr('class'),'slow');
	});
	
	// close Flyout Product
	$('#overlayLayerProduct div.closebutton').click(function(){
		$('#overlayLayerProduct').hide();		
	});

    doResize();
   	        
    // CR 1146 (sbaur): add underline styling for mouse hover to input buttons in pagenavigation_next
    $('.pagenavigation_next input').mouseover(function(){
        $(this).css('text-decoration','underline');
    });
    
    $('.pagenavigation_next input').mouseout(function(){
        $(this).css('text-decoration','none');
    });
    
    // CR 1159 (sbaur): jquery.supersleight.js extension for all png fixed on the page
    $('body').supersleight({shim: 'http://www.oswald.ch/js/x.gif'});

});




//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	//var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);

	return arrayPageSize;
}

function doResize() {
	var headerHeight = 196;
   	var browserHeight = getPageSize()[1];
   	var restHeight = browserHeight - headerHeight;
   
	if ($("#tafel").height() <=  restHeight ) {
		totalHeight = restHeight
		$("#tafel").height(totalHeight);		
	}

};

var resizeTimer = null;
$(window).bind('resize', function() {
	if (resizeTimer) clearTimeout(resizeTimer);
	resizeTimer = setTimeout(doResize, 100);
});