window.addEvent('domready',function(){
	$$('a.mytip').each(function(element,index) { var content = element.get('title').split('::'); element.store('tip:title', content[0]); element.store('tip:text', ''); });
	var tipz = new Tips('.mytip',{ className: 'mytip', fixed: false, hideDelay: 0, showDelay: 500 });
	
	if ($$('.fadeopacity').length > 0 && $('MainContent')){
		$$('.fadeopacity').each(function(obj){
			if (obj.getParents('SelectionLeftColumn').length > 0){ var parent = $('SelectionLeftColumn') } else { var parent = $('MainContent') };
			parent.addEvents({
				'mouseenter': function(){
					if (obj.getStyle('display') == 'none'){
						obj.setStyles({'opacity':0,'display':'block'});
						var myFx = new Fx.Tween(obj,{ duration: 600, transition: Fx.Transitions.Quart.easeIn }).start('opacity', 1);
					}
				}
			})
		})
	}
});

window.addEvent('load', function() {
	if($$('a.SqueezeBox').length > 0){
		ReMooz.assign('a.SqueezeBox', {
			'origin': 'img',
			'shadow': 'onOpenEnd',
			'resizeFactor': 0.8,
			'cutOut': false,
			'opacityResize': 0.4,
			'dragging': false,
			'centered': true
		});
	}
});


function SubmitForm(){
	document.location.href = $('SearchForm').get('action')+'&keywordsearch='+$('searchInput').get('value');
}

function loadUrl(url,target){
	var myHTMLRequest = new Request.HTML({
		url: url+'&lng='+lng,
		update: $(target),
		onComplete: function(){
		}}).get();
}


function AddToCart(id, quantity, image, target){
	var myHTMLRequest = new Request({
		url: 'process.addtocart.php?id='+id+'&quantity='+quantity,
		onComplete: function(response){
			if (response == 'TRUE'){
				AddToCartAnimation(image,target);
			} else {
				
			}
		}}).get();
}

function UpdateCaddyQuantity(id, quantity){
	var myHTMLRequest = new Request({
		url: 'process.addtocart.php?id='+id+'&updatequantity='+quantity,
		onComplete: function(response){
			if (response == 'TRUE'){
				ShowCaddyQuantity();
				loadUrl('include.caddy.inc.php?i=1','MainContent');
			} else {
				
			}
		}}).get();
}

function ShowCaddyQuantity(){
	var myHTMLRequest = new Request({ url: 'process.checkcaddyquantity.php', onComplete: function(response){ $$('.caddyquantity').set({'text':response}) }}).get();
}

function AddToCartAnimation(image,target){
	var copy = image.clone();
	copy.setStyles({'position':'absolute','top':image.getCoordinates().top,'left':image.getCoordinates().left,'z-index':'4000'}).inject($('Main'));
	var myEffect = new Fx.Morph(copy, { duration: 300, link:'chain', transition: Fx.Transitions.Quint.easeIn })	.start({ 'top': target.getCoordinates().top, 'left': target.getCoordinates().left+target.getCoordinates().width-40 }).start({ 'height': 20 });
	(function(){ copy.dispose(); }).delay(500);
	(function(){ ShowCaddyQuantity(); }).delay(800);
}
