function updateField(onThis){
	if($('#tmb').html()==''){
		$('#tmb').html(onThis);
	}
	if($('#tmb').html()=='#bottom' && onThis=='#top'){
		$('#tmb').html('both');
	}
	if($('#tmb').html()=='#top' && onThis=='#bottom'){
		$('#tmb').html('both');
	}
}
$(document).ready(function(){
	
	$('#addtext_page #confirmButton').remove();//remove these buttons as they are not needed on this page
	$('#addtext_page #tryAgain').remove();//remove these buttons as they are not needed on this page
	
	$("#top input").click(function(){
		var src=$(this).val();
		
		$('.top').attr({src: '/_images/text_designs/'+src+'/colours/yellow/'+window.shape+window.orientation+'T.png'});
		updateField('#top');
	});
	
	$("#bottom input").click(function(){
		var src=$(this).val();
		
		$('.bottom').attr({src: '/_images/text_designs/'+src+'/colours/yellow/'+window.shape+window.orientation+'B.png'});
		updateField('#bottom');
	});
	
	$('#addTheText').click(function(){

		$('#wholePage').show();
		$('#wholePage .content .content').html('<p align="center" style="margin-top:150px; margin-left:115px;"><img src="/_images/application/loading.gif" /></p><br /><p align="center" style="clear:both;">Loading..</p>');
		$('#wholePage').css({height:1200});
		
		if($('.top').attr('src')=='/var/www/vhosts/photo-balloon.net/httpdocs/_images/text_designs/invisi.png' && $('.bottom').attr('src')=='/var/www/vhosts/photo-balloon.net/httpdocs/_images/text_designs/invisi.png'){
			window.location ='customText.php';
			$('body').css({'overflow':'auto'});
			$('#wholePage').hide();
		}
		else{
			$.post(
					'/_core/_func/images.php',
					{
						action:'addText',
						id:$('#pid').html(),
						top:$('.top').attr('src'),
						bottom:$('.bottom').attr('src')
					},
					function(data){
						if(data=='saved'){
							$('body').css({overflow:'auto'});
							window.location = 'customText.php';
						}
						else{
							alert(data);
						}
					}
			);
		}
	});
	
	$('#top .scol').click(function(){
		var targ=$(this).attr('targ');
		
		$('.top').attr({src: '/_images/text_designs/'+$("#top .predtext:checked").val()+'/colours/'+$(this).attr('color')+'/'+window.shape+window.orientation+'T.png'});
	});
	
	$('#bottom .scol').click(function(){
		var targ=$(this).attr('targ');
		
		$('.bottom').attr({src: '/_images/text_designs/'+$("#bottom .predtext:checked").val()+'/colours/'+$(this).attr('color')+'/'+window.shape+window.orientation+'B.png'});
	});
	
	$('#customtext_page #confirmButton').click(function(){
		window.location = '/cart/';
	});
	
	$('#customtext_page #tryAgain').click(function(){
		$('#wholePage').hide();
	});
	
	$('.remove-top').click(function(){
		$('.top').attr({src:'/_images/text_designs/invisi.png'});
	});
	
	$('.remove-bottom').click(function(){
		$('.bottom').attr({src:'/_images/text_designs/invisi.png'});
	});
	
	$('#custom_submit').click(function(){
		
		$('#wholePage').show().css({'height':800});
		$('#confirmButton').remove();//remove these buttons as they are not needed on this page
		$('#tryAgain').remove();//remove these buttons as they are not needed on this page
		$('#wholePage .content .content').html('<p align="center" style="margin-top:150px; margin-left:115px;"><img src="/_images/application/loading.gif" /></p><br /><p align="center" style="clear:both;">Loading..</p>');
	});
	
});