// JavaScript Document
$(document).ready(function() {
	$("a.iframe").fancybox({
		'width' : 400,
		'height' : 400,
		'type' : 'iframe',
		'overlayOpacity' : 0.5,
		'margin' : 20,
		'padding' : 5,
		'titleShow' : false,
		'centerOnScroll' : true
	});
	$("a.iframeSmall").fancybox({
		'width' : 400,
		'height' : 200,
		'type' : 'iframe',
		'overlayOpacity' : 0.5,
		'margin' : 20,
		'padding' : 5,
		'titleShow' : false,
		'centerOnScroll' : true
	});
	
	$("a.iframeSmallNoOverflow").fancybox({
		'width' : 400,
		'height' : 200,
		'type' : 'iframe',
		'overlayOpacity' : 0.5,
		'margin' : 20,
		'padding' : 5,
		'titleShow' : false,
		'scrolling' : 'no',
		'centerOnScroll' : true
	});
	
	$("a.addToBag").each(
		function() {
			var jshref = $(this).attr('altLink');
			$(this).fancybox({
				'width' : 400,
				'height' : 400,
				'type' : 'iframe',
				'overlayOpacity' : 0.5,
				'margin' : 20,
				'padding' : 5,
				'href' : jshref,
				'titleShow' : false,
				'centerOnScroll' : true
			});
		}
	);
	
	if ($("#addedToBasket").length > 0) {
		var t = setTimeout("$('#addedToBasket').fadeOut('slow')", 5000);
	}
	
	$("a.youtubeVideo").click(function() {
		$.fancybox({
			'padding' : 2,
			'margin' : 10,
			'autoScale' : false,
			'transitionIn' : 'elastic',
			'transitionOut' : 'elastic',
			'width' : 641,
			'height' : 386,
			'overlayOpacity' : 0.7,
			'overlayColor' : '#000',
			'hideOnOverlayClick' : false,
			'centerOnScroll' : true,
			'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type' : 'swf',
			'swf' : {
			'wmode' : 'transparent',
			'allowfullscreen' : 'true'
			}
		});
		return false;
	});
});

function addToFavorites() {
	if (window.sidebar) {
		window.sidebar.addPanel(pageName, urlAddress, "");
	} else if (window.opera && window.print){
		var elem = document.createElement('a');
		elem.setAttribute('href',urlAddress);
		elem.setAttribute('title',pageName);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if (document.all) {
		window.external.addfavorite(urlAddress, pageName);
	} else {
		alert("Sorry! Your browser doesn't support this function.");
	}
}

var popup_win;
function OpenWindow(url,iWidth,iHeight) {
	var pw_left=(screen.Width-parseInt(iWidth))/2;
	var pw_top=(screen.Height-parseInt(iHeight))/2;
	
	if (!popup_win || popup_win.closed) {
		popup_win=window.open(url, 'popupwin', 'menus=0, scrollbars=auto, toolbars=0, width='+iWidth+', height='+iHeight+', screenX='+pw_left+',screenY='+pw_top+',top='+pw_top+',left='+pw_left+';');
	} else {
		popup_win.close();
		popup_win=window.open(url, 'popupwin', 'menus=0, scrollbars=auto, toolbars=0, width='+iWidth+', height='+iHeight+', screenX='+pw_left+',screenY='+pw_top+',top='+pw_top+',left='+pw_left+';');
	}
}

function writeEmail(sUser, sDomain, sClass) {
	document.write('<a href="mail' + 'to:' + sUser + '@' + sDomain + '"');
	if (sClass != '') { document.write(' class="' + sClass + '"'); }
	document.write('>' + sUser + '@' + sDomain + '</a>');
}
