$mytyShortBasket = {
	location : null,
	settings : {
		url : null,
		data : {},
		opacity : 1,
		animationDuration : 500,
		automaticClose : false,
		showTime : 4000
	},
	callbacks : {
		oncomplete : function() {}
	},
	init : function(location, settings, callbacks) {
		if (location.length>0) {
			this.configure(settings,callbacks);
			this.location = $(location[0]);
			this.create();
		}
	},
	configure : function(settings,callbacks) {
		this.settings = jQuery.extend(this.settings,settings);
		this.callbacks = jQuery.extend(this.callbacks,callbacks);
	},
	// Code erzeugen
	create : function() {
		var injectedCode = '<div class="sb-container" style="display:none;"><a href="javascript:;" class="sb-close"/><div class="sb-top"/><div class="sb-center"><div class="sb-content"/></div><div class="sb-bottom"/></div>';
		this.location.append(injectedCode);
		this.location.css('overflow','visible');
		$sb_container = $('div.sb-container');
		$sb_container.fadeTo(1, 0, function(){ $sb_container.hide(); });
		$sb_content = $('div.sb-content');
		$('a.sb-close').click( function() { $mytyShortBasket.close(); } );
	},
	show : function() {
		this.loadContents();
	},
	loadContents : function() {
		$sb_content.load(this.settings.url,this.settings.data,function() {
			$mytyShortBasket.loadCallback();
			try { this.callbacks.oncomplete; } catch(e) {}
		});
	},
	loadCallback : function() {
		$sb_container.show();
		$sb_container.fadeTo(this.settings.animationDuration, this.settings.opacity);
		if (this.settings.automaticClose==true) {
			window.setTimeout( function() { $mytyShortBasket.close(); }, this.settings.showTime);
		}
	},
	close : function() {
		$sb_container.fadeTo(this.settings.animationDuration, 0, function(){ $sb_container.hide(); });
	}
}

$mytyBasketNotice = {
	settings : {
		url : null,
		data : {},
		background_opacity : 0.8,
		opacity : 1,
		animationDuration : 1000,
		automaticClose : true,
		showTime : 4000
	},

	callbacks : {
		oncomplete : function() {}
	},

	init : function(settings, callbacks) {
		this.configure(settings,callbacks);
		this.create();

		$(window).scroll(function(){ $scrollPos = _getScroll(); $mytyBasketNotice.centerLayer(); });
		$(window).resize(function(){ $mytyBasketNotice.centerLayer(); $mytyBasketNotice.resizeOverlay(); });
	},

	configure : function(settings,callbacks) {
		this.settings = jQuery.extend(this.settings,settings);
		this.callbacks = jQuery.extend(this.callbacks,callbacks);
	},

	// Code erzeugen
	create : function() {
		var injectedCode = '<div class="mytyOverlay" id="sbn-overlay"/><div class="sbn-container" style="display:none;"><a href="javascript:;" class="sbn-close"/><div class="sbn-content"/>';
		$('body').append(injectedCode);
		$sbn_overlay = $('#sbn-overlay');
		$sbn_overlay.css('z-index','10010').css('opacity',0).hide();
		$sbn_container = $('div.sbn-container');
		$sbn_container.css('z-index','10011').fadeTo(1, 0, function(){ $sbn_container.hide(); });
		$sbn_content = $('div.sbn-content');
		$('a.sbn-close').click( function() {$mytyBasketNotice.close();} );
		this.resizeOverlay();
	},

	centerLayer : function() {
		if($.browser.opera) {
			windowHeight = window.innerHeight;
			windowWidth = window.innerWidth;
		}else{
			windowHeight = $(window).height();
			windowWidth = $(window).width();
		};
		sbnWidth = $sbn_container.width();
		sbnHeight = $sbn_container.height();
		var projectedTop = (windowHeight/2) + $scrollPos['scrollTop'] - (sbnHeight/2);
		if(projectedTop < 0) projectedTop = 0;
		$sbn_container.css({
			'top': projectedTop,
			'left': (windowWidth/2) + $scrollPos['scrollLeft'] - (sbnWidth/2)
		});
	},

	resizeOverlay : function() {
		$('div.mytyOverlay').css({
			'height':$(document).height(),
			'width':$(window).width()
		});
	},

	show : function() {
		this.loadContents();
		$sbn_overlay.show().fadeTo(this.settings.animationDuration,this.settings.background_opacity);
	},

	loadContents : function() {
		$sbn_content.load(this.settings.url,this.settings.data,function() {
			$mytyBasketNotice.loadCallback();
			try { this.callbacks.oncomplete; } catch(e) {}
		});
	},

	loadCallback : function() {
		this.centerLayer();
		$sbn_container.show();
		$sbn_container.fadeTo(this.settings.animationDuration, this.settings.opacity);
		if (this.settings.automaticClose==true) {
			window.setTimeout( function() { $mytyBasketNotice.close(); }, this.settings.showTime);
		}
	},

	close : function(callback) {
		$sbn_overlay.fadeTo(this.settings.animationDuration, 0, function() { $sbn_overlay.hide(); });
		$sbn_container.fadeTo(this.settings.animationDuration, 0, function(){ if (typeof callback!='undefined') { callback(); } $sbn_container.hide(); });
	}
}

$mytyBasketAlert = {
	settings : {
		url : null,
		data : {},
		opacity : 1,
		animationDuration : 1000,
		automaticClose : true,
		showTime : 4000
	},
	callbacks : {
		oncomplete : function() {}
	},
	init : function(settings, callbacks) {
		this.configure(settings,callbacks);
		this.create();
		$(window).scroll(function(){ $scrollPos = _getScroll(); $mytyBasketAlert.centerLayer(); });
		$(window).resize(function(){ $mytyBasketAlert.centerLayer(); });
	},
	configure : function(settings,callbacks) {
		this.settings = jQuery.extend(this.settings,settings);
		this.callbacks = jQuery.extend(this.callbacks,callbacks);
	},
	// Code erzeugen
	create : function() {
		var injectedCode = '<div class="sbn-container" style="display:none;"><a href="javascript:;" class="sbn-close"/><div class="sbn-content"/>';
		$('body').append(injectedCode);
		$sbn_container = $('div.sbn-container');
		$sbn_container.fadeTo(1, 0, function(){ $sbn_container.hide(); });
		$sbn_content = $('div.sbn-content');
		$('a.sbn-close').click( function() {$mytyBasketAlert.close();} );
	},
	centerLayer : function() {
		if($.browser.opera) {
			windowHeight = window.innerHeight;
			windowWidth = window.innerWidth;
		}else{
			windowHeight = $(window).height();
			windowWidth = $(window).width();
		};
		sbnWidth = $sbn_container.width();
		sbnHeight = $sbn_container.height();
		var projectedTop = (windowHeight/2) + $scrollPos['scrollTop'] - (sbnHeight/2);
		if(projectedTop < 0) projectedTop = 0;
		$sbn_container.css({
			'top': projectedTop,
			'left': (windowWidth/2) + $scrollPos['scrollLeft'] - (sbnWidth/2)
		});
	},

	show : function(optionId) {
		this.loadContents(optionId);
	},
	loadContents : function(optionId) {
		this.settings.data['optionId'] = optionId;
		$sbn_content.load(this.settings.url,this.settings.data,function() {
			$mytyBasketAlert.loadCallback();
			try { this.callbacks.oncomplete; } catch(e) {}
		});
	},
	loadCallback : function() {
		this.centerLayer();
		$sbn_container.show();
		$sbn_container.fadeTo(this.settings.animationDuration, this.settings.opacity);
		if (this.settings.automaticClose==true) {
			window.setTimeout( function() { $mytyBasketAlert.close(); }, this.settings.showTime);
		}
	},
	close : function(callback) {
		$sbn_container.fadeTo(this.settings.animationDuration, 0, function(){ if (typeof callback!='undefined') { callback(); } $sbn_container.hide(); });
	}
}

if (typeof _getScroll == 'undefined') {
	function _getScroll() {
		if (self.pageYOffset) {
			scrollTop = self.pageYOffset;
			scrollLeft = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
			scrollTop = document.documentElement.scrollTop;
			scrollLeft = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			scrollTop = document.body.scrollTop;
			scrollLeft = document.body.scrollLeft;
		}
		return {scrollTop:scrollTop,scrollLeft:scrollLeft};
	}
}

$(function() {
	try {
		$scrollPos = _getScroll();
		$mytyBasketNotice.init({ url: document.location.protocol+'//'+document.location.hostname+'/templates/rl2009/scripts/basketnotice.ajax.php'});
		$mytyBasketAlert.init({ url: document.location.protocol+'//'+document.location.hostname+'/templates/rl2009/scripts/basketalert.ajax.php'});
		$mytyShortBasket.init($('#shortBasket'), { url: document.location.protocol+'//'+document.location.hostname+'/templates/rl2009/scripts/shortbasket.ajax.php'} );
		tyShopBasket.configure({},{onAddComplete : function(response){
			if(typeof tyShopBasketLinkHTML !=='undefined'){
				$('#tyShopBasketLink').wrap(tyShopBasketLinkHTML);
				$('#shortBasket.sum0').removeClass('sum0').addClass('sum1');
			}
			$('#headGoToBasketBtn').show();
			$mytyBasketNotice.configure({data: response});
			$mytyBasketNotice.show();
		} });
	} catch(e) {
		if (typeof console != 'undefined') {
			console.log(e);
		} else {
		}
	}
});