var _ = jQuery.noConflict();
var teaser_timer = 0;
var home_path = location.protocol+'//'+location.hostname+location.pathname;
var saves=new Array();

jQuery(document).ready(function(){
/*
	// location
	var p = -1;
	if (-1 == (p = home_path.indexOf('bg/')))
		p = home_path.indexOf('en/');
	if (p > 0)
		home_path=home_path.substr(0, p);
*/	
	jQuery("input[name='cap_prot']").val('1');	

//	 setup
	teaser_setup();
	input_saves('#q,#nl_email');
	
	jQuery('#newsletterRegister').each(function(){
		var t = jQuery(this);
		var ff = {
	    	url: t.attr('action')+'x.php',
	    	success: function(data){	    		
	    		jQuery('#newsletterRegisterInfo').hide().html(data.substr(2)).fadeIn(600);	    		
	    		if (data.substr(0, 2) == 'OK')
	    			jQuery('#nl_email').attr('value', '');
	    	}
		};
		//t.ajaxForm(ff);
	});
	
	//
	jQuery('#productPrint,#productPrint2').click(function(){window.print();return false;});
	
	jQuery('#menuTop li').hover(function(){
		jQuery(this).addClass("over");
	}, function(){
		jQuery(this).removeClass("over");
	});
});

function input_saves(id) {
	jQuery(id).each(function(){
		var t=jQuery(this);
		if (t.length==1) {
			saves[this.id]=t.attr('value');
			t.blur(function(){
				var t=jQuery(this);
				var v=t.attr('value');
				if (v=='')
					t.attr('value', saves[this.id]);
			}).focus(function(){
				var t=jQuery(this);
				if (t.attr('value')==saves[this.id]) {
					t.attr('value','');
				}
			});
		}
	});
}

function teaser_setup(){
	//
	if(jQuery('#teaser').length != 1)
		return;
		
	//
	var c=1;
	jQuery('.teaserImg img').each(function(){
		if (1 != c++) jQuery('<img>').attr('src', jQuery(this).attr('src'))
	});

	
	//
	jQuery('#teaserNav a').click(function(){
		teaser_run(jQuery(this));
		return false;
	}).hover(function(){teaser_auto_stop();},function(){teaser_auto_start();});
	
	jQuery('.teaserImg img').hover(function(){teaser_auto_stop();},function(){teaser_auto_start();});
	
	teaser_auto_start();
}

function teaser_run(t){	
	if (t==undefined)
		return;
	if (t.attr('class')=='selected')
		return;
	teaser_auto_stop();
	var c=jQuery('.teaserImg').filter(function(){
		return jQuery(this).css('display')=='block';
	});
	var n_id = 'teaser'+t.html()
	if (n_id == c.attr('id'))
		return;
	var n=jQuery('#'+n_id);
	if (t.length != 1)
		return;
	var y=0;
	var h=n.height();
	var z=400;
	c.css('top', y).animate({top:y-h}, z, 'linear', function(){
		c.hide();
		teaser_auto_start();
	});
	n.css('top', y+h).show().animate({top:y}, z, 'linear');
	jQuery('#teaserNav a').removeClass('selected');
	t.addClass('selected');
}

function teaser_auto_start(){

	teaser_auto_stop();
	
	teaser_timer = setTimeout(function(){ 
		teaser_auto_stop();
		var curr=jQuery('#teaserNav a').filter(function(){
			return jQuery(this).attr('class')=='selected';
		});
		var who=curr.next();
		if (who.length==0)
			who=curr.siblings('a:first');
		teaser_run(who);
	},5000); // teaser speed
}

function teaser_auto_stop(){
	if (teaser_timer) {
		clearTimeout(teaser_timer);
		teaser_timer = 0;
	}
}
