$(document).ready(function() {
	var lang = $('meta:first').attr('lang');
	$('a[rel=external]').click(function(){
		this.target = "_blank";
	});
	$('#leftContent .textitem:last').css({
		'border' : 'none',
		'margin' : '10px 0 0 0'
	})
	
	$('#leftContent3 .textitem:last').css({
		'background': 'none'
	})
	
	$('#rightContent .textitem:last').css({
		'background': 'none',
		'padding'	: '0'
	})
	$('#rightContent .noback').css({
		'background': '#fff',
		'padding'	: '0'
	})
	
	$('#leftMenu li').each(function(){
		var id = $(this).find('a, span').html().toLowerCase().replace(' ', '_');
		$(this).find('a, span').html('<img src="/media/img/collections/'+id+'.gif"  alt="'+id+'" />');
		
		$(this).find('a, span').each(function(){
			var tt = $(this).attr('title');
			var ttNew = breakOn(tt,' - ');
			$(this).attr('title',ttNew);
		});
	})
	
	$('#leftMenu li a').hover(
		function(){
			$(this).css({opacity:0.5});
		},
		function(){
			$(this).css({opacity:0.7});
		}
	).tooltip({
		showURL	: false, 
		track	: true,
		fade	: 250
	})
	
	$('.materials img').tooltip({
		showURL	: false, 
		track	: true,
		fade	: 250
	})
	
	$('#leftMenu li span').css({opacity:0.3});
	$('#leftMenu li a').css({opacity:0.7});
	
	/*$.ajax({
		type	: 'POST',
		url		: '/new/ajax.php',
		data	: {
			f	: 'getFolderImage',
			id	: '1229'
		},
		success	: function(data){
			var lnk = 'Play';
			$('#productPicture .productimg').attr('src', '/new/media/img/pics/_product/'+data);
		}
	})*/
	var email = $('#newsLetter').val()
	$('#newsLetter').focus(function(){
		if($(this).val() == email){
			$(this).val('');
			$(this).css({'color':'#282828'})
		}
	})
	
	$('#newsLetter').blur(function(){
		if($(this).val() == '' || $(this).val() == email){
			$(this).val(email);
			$(this).css({'color':'#bbb'})
		}
	})
	
	$('#newsLetterBtn').bind('click', function(){
		var email = $('#newsLetter').val();
		if(!validMail(email)){
			$('#error').html('Your e-mail is not correct.');
		}else{
			$.ajax({
				url		: '/new/ajax.php',
				type	: 'POST',
				data	: {
					emailAdres : email
				},
				success	: function(){
					$('#newsLetter').attr('disabled', 'disabled');
					$('#newsLetter').css({
						'color'	: '#00aa00'
					})
					$('#error').html('');
					$('#newsLetter').val('You are now subscribed for the newsletter.')
					
				}
			
			})	
		}
	})
	
});

function breakOn(txt, brtxt){
	var txtNew = '';
	for(i=0; i<txt.length; i++){
		if(txt.substring(i,i+brtxt.length) == brtxt){
			return txtNew;
		} else {
			txtNew = txtNew+txt.substring(i,i+1);
		}
	}
	return(txtNew);
}

function getImgSize(src, obj){
	
	var imgTesting = new Image();
	imgTesting.onload = CreateDelegate(imgTesting, imgTesting_onload);
	imgTesting.src = src;

	//alert(imgTesting.height);
	obj.css({'height' : imgTesting.height+'px'});
	obj.find('a, span').css({'display':'block', 'height':'100%'})
	/*var h = '';
	$.ajax({
		async	: false,
		url		: '/new/ajax.php',
		type	: 'POST',
		data	: {
			f	: 'getImageHeight',
			src	: src	
		},
		success	: function(data){
			obj.css({'height' : data+'px'});
			obj.find('a, span').css({'display':'block', 'height':'100%'})
		}
	})*/
}

function CreateDelegate(contextObject, delegateMethod)
{
    return function()
    {
        return delegateMethod.apply(contextObject, arguments);
    }
}

function imgTesting_onload()
{
    return(this.height);
}
