$(document).ready(function() 
{
	if($('#productlist.style')[0]) {
		$('#subnav_back').show();
		$('#subnav_back').unbind();
		$('#subnav_back').bind('click', function(){history.back()});
	}
	
	/*
	 * Einstellungen
	 */
	var show_nav_images = true;
	
	/*
	 * Topnavigation
	 */	
	var doOpenTopnav 	= true; 
	var topnavIndex		= 0;
	/* für alle Level */
	$('#topnav .products').bind('mouseenter', function(e){
		doOpenTopnav = true;
		window.setTimeout(function() {
			if(doOpenTopnav) {
				$('#topnav .products ul.level1').fadeIn('fast');
			}
		});
	});
	
	$('#topnav .products').bind('mouseleave', function(e){
		doOpenTopnav = false;
		
		$('#overlay').hide();
		$('#topnav ul.level1').hide();
	});
	
	$('#topnav .products ul.level2 li').bind('mouseenter', function(e){
		var int_newTop = $(this).offset().top - 49;
		$('#n' + this.value).css('top', int_newTop + 'px');		
		$('#n' + this.value).show();
	});
	
	
	// Vorschaubilder in der Navigation
	if(show_nav_images) {
		var nav_image_width = 138 + 3; // + margin
		var nav_image_height = 138 + 3; // + margin
		$('#topnav .products ul>li').bind('mouseenter', function(e){
			var images_count = 0;
	
			$(this).find('>ul>li>a>img').each(function(e) {
				images_count++;
			});
			
			if(images_count) {
				var offset = $('#n10').offset().top;
				var height = $('#n10').height();
				var ul = $(this).find('>ul');
				var li = $(this).find('>ul>li');
				
				$(this).css('margin', '0');
				$(this).css('padding', '0');
				
				li.find('a').css('border', 'none');
				li.find('a').css('margin', '0');
				li.find('a').css('padding', '0');
				li.find('a').css('width', 'auto');
				li.find('.name').css('display', 'none');
				li.find('img').css('display', 'block');
				li.find('img').css('border', 'none');
				li.find('img').css('margin-right', '3px');
				li.find('img').css('margin-bottom', '3px');
				li.find('img').css('padding', '0');
				
				var cols;
				var rows;
				switch(images_count) {
					case 6:
						cols = 3;
						rows = 6;
					break;			
				
					case 5:
						cols = 3;
						rows = 2;
					break;
					
					case 4:
						cols = 2;
						rows = 2;
					break;
					
					case 3:
						cols = 3;
						rows = 1;				
					break;
					
					case 2:
						cols = 2;
						rows = 1;				
					break;
					
					case 1:
						cols = 1;
						rows = 1;				
					break;					
				}
				
				ul.css('width', 15 + nav_image_width * cols + 'px');
				ulheight = nav_image_height * rows;		
					
				var new_offset = (height + offset - ulheight - 67) + 'px';
				ul.css('top', new_offset);			
				
				ul.css('background-color', '#f0f0f0');
				ul.css('margin', '0');
				ul.css('padding', '10px');
				
				ul.css('padding-right', '7px'); // Anpassung für margin
				ul.css('padding-bottom', '7px'); // Anpassung für margin
				
				ul.css('border', '1px solid #d2d2d2');
				ul.css('border-left', 'none');
				
				li.css('width',  nav_image_width + 'px');
				li.css('float', 'left');
				li.css('margin', '0');
				li.css('padding', '0');
				li.css('border', 'none');
			}
		});
	}
	
	$('#topnav .products ul.level2 li').bind('mouseleave', function(e){
		$('#n' + this.value).hide();
	});
	
	// Xmas
	$('#topnav .xmas').bind('mouseenter', function(e){
		doOpenTopnav = true;
		window.setTimeout(function() {
			if(doOpenTopnav) {
				$('#topnav .xmas ul.level1').fadeIn('fast');
			}
		});
	});
	
	$('#topnav .xmas').bind('mouseleave', function(e){
		doOpenTopnav = false;
		
		$('#overlay').hide();
		$('#topnav ul.level1').hide();
	});
	
	$('#topnav .xmas ul.level2 li').bind('mouseenter', function(e){
		var int_newTop = $(this).offset().top - 49;
		$('#n' + this.value).css('top', int_newTop + 'px');		
		$('#n' + this.value).show();
	});
	
	$('#topnav .xmas ul.level2 li').bind('mouseleave', function(e){
		$('#n' + this.value).hide();
	});
	
	/*
	 * Subnavigation
	 */
	$('#subnav ul li').bind('mouseenter', function(e){
		$('#n' + this.value).show();
	});	
	
	$('#subnav ul li').bind('mouseleave', function(e){
		$('#n' + this.value).hide();
	});
	
	/* ab Level1 */
	$('#subnav ul.level1 li').bind('mouseenter', function(e){
		var int_newTop = $(this).offset().top - $(this).parent().offset().top;
		$('#n' + this.value).css('top', int_newTop + 'px');
	});
	
	/*
	 * Sigel Style Navigation
	 */
	// Style-Navigation aktivieren wenn es Flash gibt
	if($('#sigel_style_nav_overlay').length != 0) {
		var so = new SWFObject('dummy', 'flash', '1', '1', '8');
		so.write('sigel_style_nav_overlay');
		if($('#sigel_style_nav_overlay').html()) {
			$('#sigel_style_nav').show();
		} else {
			$('#sigel_style_nav_nonflash').show();	
		}
	}

	// Overlay
	var doOpenStylenav = true;
	var sigel_style_nav_overlay_loaded = false;
	$('#sigel_style_nav').bind('mouseenter', function(e){
		doOpenStylenav = true;
		window.setTimeout(function() {
			if(doOpenStylenav) {
				if(!sigel_style_nav_overlay_loaded) {
					var so = new SWFObject('/img/shared/sigel_style_navigation.swf', 'navFlash', '100%', '494', '8'); 
					so.addParam('wmode', 'opaque');
					so.write('sigel_style_nav_overlay');
					sigel_style_nav_overlay_loaded = true;
				}
				
				$('#sigel_style_nav').attr('class', 'sigel_style active');
				$('#sigel_style_nav_overlay').show();
			}
		}, 500);	
	});
	
	$('#sigel_style_nav').bind('mouseleave', function(e){
		doOpenStylenav = false;
		$('#sigel_style_nav_overlay').hide();
		$('#sigel_style_nav').attr('class', 'sigel_style');
	});


	/*
	 * Grössen u.a. dynamisch anpassen
	 */
		
	// Tabhöhe
	if($('#wrapper').css('height') == '560px') {
		var intWrapperHeight = $('#wrapper').css('height').replace('px', '');
		var intTabsOffsetTop = $('#tabs').offset().top;
		var intTabsHeight = intWrapperHeight - intTabsOffsetTop - 15;
		
		if($('#teaser').length > 0) {
			var intTeaserMarginTop = parseInt($('#teaser').css('margin-top').replace('px', ''));
			intTabsHeight -=  + $('#teaser').height() + intTeaserMarginTop;
		}
		
		$('#tabs .tab').css('height', intTabsHeight + 'px');
	}
	
	// Productlisten
	initProductlist();
	
	
	/*
	 * Flash
	 */
	
	// Fullflash
	$('#primary').stop(true);
	$('#primary').hide();
	$('#primary').css('visibility', 'visible');
	
	if($('#flash').attr('alt') != '') {
	   var so = new SWFObject('/assets/' + $('#flash').attr('alt'), 'flash', '100%', '100%', '8'); 
	   so.addParam('wmode', 'opaque');
	   so.addVariable('dataXML', $('meta[name="params"]').attr('content'));
	   so.addVariable('deeplink', $(document).attr('location').hash.substring(1));
	   so.write('flash');
	   
	   if($('#flash').html() == '') {
	   		// no flash
	   		$('#primary').stop(true);
			$('#primary').show();
			$("#teaser_bottom").hide();
			// "DurchFlackern" des Hintergrunds vermeiden:
			// Hg-Bild und Farbe werden nur gesetzt, wenn tatsächlich no-Flash Version
			// erforderlich ist. Variablen bgImgSave und bgColorSave werden direkt im HTML
			// Template definiert
			setTimeout("delayedBackgroundLoad()",500);
	   } else {
			// flash
			$('#primary').stop(true);
			$('#primary').hide();
			$('#flash').show();
			setTimeout("delayedBackgroundLoad()",3000);
	   }
	   
	   
	} else {
		$("#teaser_bottom").hide();
		$('#primary').stop(true);
		$('#primary').show();
	}
	

	$('#wrapper').show();
	
	/*
	var strBgImage = $('#wrapper').attr('alt');
	$('#wrapper').css('background-image', 'url("'+strBgImage+'")');
	*/

	// Inline
	$('.inlineflash').each(function(e) {
		var swf = $(this).attr('title');
		var width = $(this).attr('width');
		var height = $(this).attr('height');	
			
		var id = $(this).attr('id');
		var so = new SWFObject(swf, 'inlineflash', width, height, '8');
		
		so.addParam('scale', 'noscale');
		so.addParam('wmode', 'opaque');
		so.addVariable('dataXML', $('meta[name="params"]').attr('content'));
		so.write(id);	
	});
	

	/*
	 * Schnellsuche
	 */
	var quicksearch_process = false;
	$('#query').bind('keyup', function(e) {
		var query = $('#query').attr('value');
		
		if(query.length > 1) {
			$('#quicksearch .all_hits>a').attr('href', '/search/index/'+query);
			
			if(quicksearch_process) {
				stop();
			}
			
			quicksearch_process = true;
			$('#quicksearch .list').html('<ul/>');
			
			$.getJSON('/search/quicksearch/'+query, function(json){
				$.each(json, function(index, hit){
					$('#quicksearch .list').append('<li><a href="'+hit.uri+'">'+hit.name+'</a></li>');
				});
								
				$('#quicksearch').slideDown('slow');
				
				
				// Bei Click ausserhalb wieder zu machen
				$(document).click(function(){
				    $('#quicksearch').slideUp('slow');
				});
				
				$('#quicksearch').click(function(e){
				    e.stopPropagation();
				});
				
				
				quicksearch_process = false;
			});
		}
	});
	
	/*
	 * Vergleichen
	 */
	
	// Maximal 5 Produkte auswählen
	$('#productlist input[name="compare"]').bind('click', function(e){
		if($('#productlist input[name="compare"]:checked').length > 5) {
			alert(txt_compare2);
			$(this).attr('checked', false);
		}
	});
	
	ajaxlinks();
	
	// Footer
	$('#footer').css('top', $(document).height());
});


function delayedBackgroundLoad(){
	$('#wrapper').css('background-image', bgImgSave);
	$('#wrapper').css('background-color', bgColorSave);	
}


/*
 * Links per Ajax laden
 */
function ajaxlinks()
{
	if(!$('.filter')[0]) {
		$('.tfoot .ajax').bind('click', function(e){
			ajaxload_tab1($(this).attr('href'));
			return false;
		});
	}
	
	$('.ajaxload').bind('click', function(e){
		ajaxload_tab2($(this).attr('href'), $(this).attr('alt'), $(this).attr('rev'));
		return false;
	});
}

function ajaxload_tab1(strUrl, strTabname, strClosebutton)
{
	$("#productlist").load(strUrl, function() {
		initProductlist();
		ajaxlinks();
		window.scrollTo(0,0);
	});
}

function ajaxload_tab2(strUrl, strTabname, strClosebutton)
{
	var objLastActiveTab = $("#subnav ul.level0 li.active");
	
	$("#tab2").load(strUrl, function(){
		$("#tabs .tab").hide();
		
		if(strTabname) {
			$("#subnav ul.level0 li").attr('class', '');
			$('#subnav ul.level0').append('<li id="tab_1" class="active"><a href="#">'+strTabname+'</a></li>');
		}		
		
		if(strClosebutton) {
			$("#tab2 .inner").prepend('<div class="header"><a href="Javascript:void(0);" id="closebutton" class="button_blue">'+strClosebutton+'</a></div>');
			$("#mediabox #controllbar").css('top', '340px');
			$("#mediabox #thumbs").css('top', '387px');
			
			$('#closebutton, #tab_1').bind('click', function(e) {
				$('#tab_1').remove();
				$('#tab2').hide();
				$('#tab1').show();
				$(objLastActiveTab).attr('class', 'active');
			});
		}
		$('#subnav_back').attr('class', 'active');
		
		$("#tab2").show();
		window.scrollTo(0,0);
	});
}

/*
 * Produktlisten
 */
function initProductlist()
{
	if($('#wrapper').css('height') == '560px') {
		/* Scrollbereich Produktlisten anpassen */
		var intWrapperHeight = $('#pageend').offset().top;
		var intTabOffsetTop = $('#productlist').offset().top;
		
		var intTabAvailableHeight = intWrapperHeight - intTabOffsetTop - 16;
		var intBodyHeight = intTabAvailableHeight;
		
		if($('#productlist').length > 0) {
			$('#tab1').css('overflow', 'hidden');
		}
		
		if($('#productlist .thead').length > 0) {
			var intHeaderHeight = $('#productlist .tbody').offset().top - $('#productlist .thead').offset().top;
			intBodyHeight -= intHeaderHeight;
		}
		
		if($('#productlist .tfoot').length > 0) {
			var intFooterHeight = $('#productlist .end').offset().top - $('#productlist .tfoot').offset().top;
			intBodyHeight -= intFooterHeight;
		}
	
		$('#productlist .tbody').height(intBodyHeight + 'px');
	}
}


/*
 * Vergleichen
 */
function CompareClose()
{
	$('#tab3').hide();
	$('#tab1').show();
}

function CompareOpen(intStart)
{
	var maxProducts = 3;
	var objCompareChecked = $('#productlist input[name="compare"]:checked');

	if(!objCompareChecked[1]) {
		alert(txt_compare1);
	} else {
		if(!intStart) {
			intStart = 0;
		}	
		
		var strEANlist = '';
		for(x=intStart; x < maxProducts + intStart; x++) {
			if(objCompareChecked[x]) {
				strEANlist += objCompareChecked[x].value + ',';
			}
		}
		
		// letztes Komma entfernen
		strEANlist = strEANlist.substr(0, strEANlist.length-1);
		
		$('#tab3').load('/products/compare/' + strEANlist, function(e) {
			
			if(intStart > 0) {
				$('#compare_prev').show();
			}
			
			if(objCompareChecked.length > maxProducts - intStart) {
				$('#compare_next').show();
			}

			$('#tab1').hide();
			$("#tab3").show();
			
			ajaxlinks();
		});
		
		
		// Scrollbars
		/*$('#comparelist tbody').jScrollPane({
			showArrows: true,
			scrollbarWidth: 15
		});*/
	}
}

function CompareDeleteProduct(strProductEan)
{
	$('#product_' + strProductEan + ' input[name="compare"]').attr('checked', false);
	CompareOpen();
}


/**
 * Mediabox
 */
function initMediabox()
{
	if($('#mediabox')) {
		var zoomSteps = 300;
		var firstSize = 300;
		var size = firstSize;
		var img;
		
		$('#dragimage').draggable({ cursor: 'move' });
		
		$('#mediabox #controllbar>#zoom_in').bind('click', function(e){
			size = size + zoomSteps;
						
			if(size <= 1200) {
				var arrImgSrc = $("#bigimage>img").attr('src').split('/');
				arrImgSrc.reverse();
				img = new Image();
				$(img).load(
					function() {
						$("#bigimage>img").attr('src', $(img).attr('src'));
					})
					.attr('src', '/medias/products/sizes/'+ size +'x'+ size +'/' + arrImgSrc[0]);
			}
			
			
						
			$("#bigimage>img").attr('width', size);
			$("#bigimage>img").attr('height', size);
			
			var newTop = $("#bigimage>img").css('top').replace(/px/, '') - (zoomSteps / 2);
			var newLeft = $("#bigimage>img").css('left').replace(/px/, '') - (zoomSteps / 2);
			$("#bigimage>img").css('top', newTop + 'px');
			$("#bigimage>img").css('left', newLeft + 'px');
		});

		
		$('#mediabox #controllbar>#zoom_out').bind('click', function(e){
			if(size - zoomSteps >= firstSize) {
				size = size - zoomSteps;
				
				if(size <= 1200) {
					var arrImgSrc = $("#bigimage>img").attr('src').split('/');
					arrImgSrc.reverse();
					img = new Image();
					$(img).load(
						function() {
							$("#bigimage>img").attr('src', $(img).attr('src'));
						})
						.attr('src', '/medias/products/sizes/'+ size +'x'+ size +'/' + arrImgSrc[0]);
				}
				
				$("#bigimage>img").attr('width', size);
				$("#bigimage>img").attr('height', size);
				
				var newTop = parseInt($("#bigimage>img").css('top').replace(/px/, '')) + (zoomSteps / 2);
				var newLeft = parseInt($("#bigimage>img").css('left').replace(/px/, '')) + (zoomSteps / 2);
				
				$("#bigimage>img").css('top', newTop + 'px');
				$("#bigimage>img").css('left', newLeft + 'px');
			}
		});
		
		$('#mediabox #controllbar>#default').bind('click', function(e){
			size = firstSize;
			
			var arrImgSrc = $("#bigimage>img").attr('src').split('/');
			arrImgSrc.reverse();
			$("#bigimage>img").attr('src', '/medias/products/sizes/'+ size +'x'+ size +'/' + arrImgSrc[0]);			
			
			$("#bigimage>img").attr('width', size);
			$("#bigimage>img").attr('height', size);
			$("#bigimage>img").css('top', 0);
			$("#bigimage>img").css('left', 0);
		});
		
		
		// Bilder wechseln
		$('#mediabox #thumbs .thumb').bind('click', function(e) {
			$('#bigimage').attr('style', 'background: url(\'/img/shared/ajax-loader.gif\') no-repeat center');
						
			size = firstSize;
			$("#bigimage>img").attr('width', size);
			$("#bigimage>img").attr('height', size);
			$("#bigimage>img").css('top', 0);
			$("#bigimage>img").css('left', 0);			
			$("#bigimage>img").attr('src', '/medias/products/sizes/300x300/' + $(this).attr('alt'));
		});
		
		
		// Icon Zustände
		var zoom_out_style = 'background-position: 0 -20px;';
		$('#mediabox #controllbar').bind('click', function(e){
			if(size > firstSize) {
				$('#mediabox #controllbar>#zoom_out').attr('style', 'background-position:0 0;');
				zoom_out_style = 'background-position:0 0;';
			} else {
				$('#mediabox #controllbar>#zoom_out').attr('style', 'background-position:0 -20px;');
				zoom_out_style = 'background-position:0 -20px;';
			}
		});
		
		// Icon Mouseover
		$('#mediabox #controllbar>#zoom_out').bind('mouseenter', function(e){
			$('#mediabox #controllbar>#zoom_out').attr('style', 'background-position: 0 -40px;');
		});
		
		$('#mediabox #controllbar>#zoom_out').bind('mouseleave', function(e){
			$('#mediabox #controllbar>#zoom_out').attr('style', zoom_out_style);
		});
		
		$('#mediabox #controllbar>#zoom_in').bind('mouseenter', function(e){
			$('#mediabox #controllbar>#zoom_in').attr('style', 'background-position: -20px -40px;');
		});
		
		$('#mediabox #controllbar>#zoom_in').bind('mouseleave', function(e){
			$('#mediabox #controllbar>#zoom_in').attr('style', 'background-position: -20px 0px;');
		});

		$('#mediabox #controllbar>#default').bind('mouseenter', function(e){
			$('#mediabox #controllbar>#default').attr('style', 'background-position: -40px -40px;');
		});
		
		$('#mediabox #controllbar>#default').bind('mouseleave', function(e){
			$('#mediabox #controllbar>#default').attr('style', 'background-position: -40px 0px;');
		});
	}
}

function OpenTab1(strUri)
{
	CloseProductdetails();
	$("#teaser").hide();
	$("#tab1").load(strUri, function() {
		initProductlist();
	});
}

function OpenProductdetails(strUri, blnInline)
{
	$("#tabs .tab").hide();

	$("#subnav ul li").attr('class', '');
	$("#subnav_back").attr('class', 'active');
	$("#subnav_productdetails").attr('class', 'active');
	$("#subnav_productdetails").show();
	
	$("#tab2").load('/products/details/' + strUri);
	$("#tab2").show();
	
	return true;
}

function CloseProductdetails()
{
	$("#subnav_productdetails").hide();
	$("#subnav>ul>li").attr('class', 'active');
	
	$("#tab2").hide();
	$("#tab2").html('');
	$("#tab1").show();
}

function ShowTab1()
{
	$("#tabs .tab").hide();
	$("#tab1").show();
}

function CloseContent()
{
	ShowFlash();
}

function AddToBasket(strEan, intAmount)
{
	if(!intAmount) {
		intAmount = 1;
	}
	
	if(typeof AddToBasketCustom == 'function') {
		AddToBasketCustom(strEan, intAmount);
	} else { 
		$("#popup").html('<img src="/img/shared/ajax-loader.gif" />');
		$("#popup").fadeIn();	
	
		var strRedirect = location.pathname + location.hash;
		
		$.getJSON('/solutionshops/basket/add?ean=' + strEan + '&amount=' + intAmount + '&redirect=' + strRedirect, '1', function(data) {
			if(data.method == 'front') {
				if(data.target == 'self') {
					self.location = data.url;
				} else if(data.target == 'opener') {
					window.opener.location.href = data.url;
					$("#popup").fadeOut();
				} else {
					window.parent.location = data.url;
				}
			} else {
				$('#popup').html(data.text + '<br/><br/><a class="button_blue" href="Javascript:void(0)" onclick="$(\'#popup\').fadeOut();">OK</a>');
			}
		});
	}
}

function InitScrollbar(element) 
{
		$('#productdetails').jScrollPane({
   			showArrows: true,
   			scrollbarWidth: 15
   		});
   		    		
   		$('.jScrollPaneContainer').css('width', ($('.jScrollPaneContainer').width()-5)+'px');
   		$('.jScrollPaneContainer').css('margin-top', '-1px');
}

function _Flash_Closehandler()
{
	//$('#main').click(function(){
	//	$('#flash').fadeIn();
	//	$('#primary').stop(true);
	//	$('#primary').hide();
	//	$("#teaser_bottom").show();
	//});
	
	$('#primary').click(function(e){
	    e.stopPropagation();
	});
}

function ShowFlash()
{
	$('#tab_1').remove();
	$("#teaser_bottom").show();
	
	$('#flash').css('top', '0');
	$('#flash').fadeTo('fast', 1, function() {
		$('#primary').stop(true);
		$('#primary').hide();
	});
	
	if ($('#footer.xmas')[0]) {
		$('#footer').hide('fast', function(){
			$('#footer').css('top', $(document).height());
			$('#footer').show();
		});
	}
}

function Flash_ShowProductlist() 
{
	CloseProductdetails();
	
	$("#teaser_bottom").hide();
	
	$("#subnav_back").unbind();
	$("#subnav_back").bind('click', function(e){
		ShowFlash();
		return false;
	});	
	
	$("#subnav_back").show();
	$('#primary').stop(true);
	$('#primary').show();
	$('#flash').fadeTo('fast', 0, function() {
		$('#flash').css('top', '-2000px');	
	});
	
	_Flash_Closehandler();

	if ($('#footer.xmas')[0]) {
		$('#footer').hide('fast', function(){
			$('#footer').css('top', $(document).height());
			$('#footer').show();
		});
	}
}

function Flash_ShowProductdetail(strUri) 
{
	$("#teaser_bottom").hide();
	
	$("#subnav_back").unbind();
	$("#subnav_back").bind('click', function(e){
		ShowFlash();
		return false;
	});	
	$("#subnav_back").show();
	$('#primary').stop(true);
	$('#primary').show();
	$('#flash').fadeTo('fast', 0, function() {
		$('#flash').css('top', '-2000px');	
	});
	
	OpenProductdetails(strUri, 1);
	
	_Flash_Closehandler();	

	if ($('#footer.xmas')[0]) {
		$('#footer').hide('fast', function(){
			$('#footer').css('top', $(document).height());
			$('#footer').show();
		});
	}
}

function Flash_SwitchHtml()
{
	$('#flash').fadeTo('fast', 0, function() {
		$('#flash').css('top', '-2000px');	
	});	
	$("#teaser_bottom").hide();
	$('#primary').stop(true);
	$('#primary').show();

	if ($('#footer.xmas')[0]) {
		$('#footer').hide('fast', function(){
			$('#footer').css('top', $(document).height());
			$('#footer').show();
		});
	}
}

function switchLogo(styleLine)
{
	if(styleLine == 'eyestyle' || styleLine == 'conceptum' || styleLine == 'pure' || styleLine ==  'diamonds') {
		$('#logo a img').attr('src', '/img/shared/sigel_logo_grey.png');
	} else {
		$('#logo a img').attr('src', '/img/shared/sigel_logo_green.png');
	}
	
	$('#logo a img').supersleight();
}

var showshowopenpopupWindow=null;
function showpopup (mypage,myname,w,h,pos,infocus)
{
 if(pos=='random'){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=='center'){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	} else if((pos!='center' && pos!='random') || pos==null){
		LeftPosition=100;TopPosition=100;
	}
	var settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';

    var showopenpopupWindow=window.open('',myname,settings);
    if(infocus=='front'){
		showopenpopupWindow.focus();
		showopenpopupWindow.location=mypage;
	}
}

function ShowBitsPaperShipping()
{
  showpopup('http://www.bitspaper.net/bpstore/ShowContent.aspx?id=5#a5','versand','620','620','center','front');
}