
	function randomXToY(minVal,maxVal,floatVal)
		{  
			var randVal = minVal+(Math.random()*(maxVal-minVal));  
			return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
		}
		
	rand1 = randomXToY(12000, 18000); setInterval( "ajaxtest(1);", rand1 );
	rand2 = randomXToY(12000, 18000); setInterval( "ajaxtest(2);", rand2 );
	rand3 = randomXToY(12000, 18000); setInterval( "ajaxtest(3);", rand3 );

function ajaxtest(img) 
	{
	
		if(img == 1)
			{

				function ShowResult1(data)
					{				
						if($('#img1_two').hasClass('img1_active'))
							{
								$("#img1_one").addClass('img1_active');
								$("#img1_two").removeClass('img1_active');
							}
						else
							{
		
								$("#img1_two").addClass('img1_active');
								$("#img1_one").removeClass('img1_active');									
							}
							
							if(!$("#img-cache img").hasClass('preload_img_'+data.preload))
								{
									val = "images/sliders/"+data.preload;
									$('<img/>').attr('src', val).appendTo('#img-cache');
									$("#img-cache img:last-child").addClass('preload_img_'+data.preload);
								}

						$(".img1_active").attr({ src: "images/sliders/"+data.img });	
					}
		
				var options = { 
								success:	ShowResult1,
								url:		'slider.php?i=1',
								type:      	'get',
								dataType:  	'json'
							  }; 
				
				$.ajax(options);
			}
			
		if(img == 2)
			{
				function ShowResult2(data)
					{				
						if($('#img2_two').hasClass('img2_active'))
							{
								$("#img2_one").addClass('img2_active');
								$("#img2_two").removeClass('img2_active');
							}
						else
							{
		
								$("#img2_two").addClass('img2_active');
								$("#img2_one").removeClass('img2_active');									
							}
							
						if(!$("#img-cache img").hasClass('preload_img_'+data.preload))
								{
									val = "images/sliders/"+data.preload;
									$('<img/>').attr('src', val).appendTo('#img-cache');
									$("#img-cache img:last-child").addClass('preload_img_'+data.preload);
								}	
		
						$(".img2_active").attr({ src: "images/sliders/"+data.img });		
					}
		
				var options = { 
								success:	ShowResult2,
								url:		'slider.php?i=2',
								type:      	'get',
								dataType:  	'json'
							  }; 
				
				$.ajax(options);
			}
			
		if(img == 3)
			{
				function ShowResult3(data)
					{				
						if($('#img3_two').hasClass('img3_active'))
							{
								$("#img3_one").addClass('img3_active');
								$("#img3_two").removeClass('img3_active');
							}
						else
							{
		
								$("#img3_two").addClass('img3_active');
								$("#img3_one").removeClass('img3_active');									
							}
							
							
						if(!$("#img-cache img").hasClass('preload_img_'+data.preload))
								{
									val = "images/sliders/"+data.preload;
									$('<img/>').attr('src', val).appendTo('#img-cache');
									$("#img-cache img:last-child").addClass('preload_img_'+data.preload);
								}
						$(".img3_active").attr({ src: "images/sliders/"+data.img });	
					}
		
				var options = { 
								success:	ShowResult3,
								url:		'slider.php?i=3',
								type:      	'get',
								dataType:  	'json'
							  }; 
				
				$.ajax(options);
			}
	}
	
function toggleEditor(id) 
			{ 
				if (!tinyMCE.get(id)) 
					{
						tinyMCE.execCommand('mceAddControl', false, id); 
					}
				else 
					{				
						tinyMCE.execCommand('mceRemoveControl', false, id); 
					} 
			}

$(document).ready(function() {
	// Add hidden element
	
	var hidden = $('body').append('<div id="img-cache" style="display:none/>').children('#img-cache');	
	
	// initialise 
	
	function ShowResult4(data)
					{				
						val = "images/sliders/"+data.img1;
						$('<img/>').attr('src', val).appendTo('#img-cache');
						$("#img-cache img:last-child").addClass('preload_img_'+data.img1);
						
						
						val = "images/sliders/"+data.img2;
						$('<img/>').attr('src', val).appendTo('#img-cache');
						$("#img-cache img:last-child").addClass('preload_img_'+data.img2);
						
						val = "images/sliders/"+data.img3;
						$('<img/>').attr('src', val).appendTo('#img-cache');
						$("#img-cache img:last-child").addClass('preload_img_'+data.img3);		
					}
		
				var options = { 
								success:	ShowResult4,
								url:		'slider.php?i=init',
								type:      	'get',
								dataType:  	'json'
							  }; 
				
				$.ajax(options);
	//blindX,blindY,blindZ,cover,curtainX,curtainY,fade,fadeZoom,growX,growY,none,scrollUp,scrollDown,scrollLeft,scrollRight,scrollHorz,scrollVert,shuffle,slideX,slideY,toss,turnUp,turnDown,turnLeft,turnRight,uncover,wipe,zoom
	var transitions = 'blindX,blindY,blindZ,cover,curtainX,curtainY,fade,fadeZoom,growX,growY,scrollUp,scrollDown,scrollLeft,scrollRight,scrollHorz,scrollVert,slideX,slideY,turnUp,turnDown,turnLeft,turnRight,uncover,wipe,zoom';
	
	$('#images #img1').cycle({
		fx: transitions,
		timeout: rand1
	});
	
	$('#images #img2').cycle({
		fx: transitions,
		timeout: rand2
	});
	
	$('#images #img3').cycle({
		fx: transitions, 
		timeout: rand3
	});
	

	$(".login_toggle").click(function(e) // Open and Close login box
	{          
		e.preventDefault();
	if ($("#login_overlay").is(':visible'))  
		{
			$("#login_overlay").hide();
		}
	else 
		{
			$("#login_overlay").show();
		}

	 });
	 
	 // Transport checkbox
	 $("#tinsurance").click(function(){
        
        // If checked
        if ($("#tinsurance").is(":checked"))
        {
            //show the hidden div
            $("#tinsval").show("fast");
			$("#tinsvaltitle").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#tinsval").hide("fast");
			$("#tinsvaltitle").hide("fast");		
        }
      });
	  
	  // Storage checkbox
	  $("#stinsurance").click(function(){
        
        // If checked
        if ($("#stinsurance").is(":checked"))
        {
            //show the hidden div
            $("#stinsval").show("fast");
			$("#stinsvaltitle").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#stinsval").hide("fast");
			$("#stinsvaltitle").hide("fast");		
        }
      });
	  
		// Shipping checkbox	  
	   $("#shinsurance").click(function(){
        
        // If checked
        if ($("#shinsurance").is(":checked"))
        {
            //show the hidden div
            $("#shinsval").show("fast");
			$("#shinsvaltitle").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#shinsval").hide("fast");
			$("#shinsvaltitle").hide("fast");		
        }
      });
	  
	  // Hiab checkbox	  
	   $("#hiinsurance").click(function(){
        
        // If checked
        if ($("#hiinsurance").is(":checked"))
        {
            //show the hidden div
            $("#hiinsval").show("fast");
			$("#hiinsvaltitle").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#hiinsval").hide("fast");
			$("#hiinsvaltitle").hide("fast");		
        }
      });
	  
	  // Public sculpture checkbox	  
	   $("#puinsurance").click(function(){
        
        // If checked
        if ($("#puinsurance").is(":checked"))
        {
            //show the hidden div
            $("#puinsval").show("fast");
			$("#puinsvaltitle").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#puinsval").hide("fast");
			$("#puinsvaltitle").hide("fast");		
        }
      });
	 
	 // Exhibition checkbox	  
	   $("#exinsurance").click(function(){
        
        // If checked
        if ($("#exinsurance").is(":checked"))
        {
            //show the hidden div
            $("#exinsval").show("fast");
			$("#exinsvaltitle").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#exinsval").hide("fast");
			$("#exinsvaltitle").hide("fast");		
        }
      });
	  
	  // Packing checkbox	  
	   $("#painsurance").click(function(){
        
        // If checked
        if ($("#painsurance").is(":checked"))
        {
            //show the hidden div
            $("#painsval").show("fast");
			$("#painsvaltitle").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#painsval").hide("fast");
			$("#painsvaltitle").hide("fast");		
        }
      });
	 
$("#login_overlay").mouseup(function() // Allow content to be entered into login box without it being closed
	{
		return false
	});
	
	// set tooltips
	
	$("#enquiry :input").tooltip({
		position: "center right",
		offset: [-2, 10],
		effect: "fade",
		opacity: 0.9
	});
	
	$("#quoteform .tl:input").tooltip({
		position: "center left",
		offset: [0, -20],
		effect: "fade",
		opacity: 0.9
	});
	
	$("#quoteform .tr:input").tooltip({
		position: "center right",
		offset: [-2, 10],
		effect: "fade",
		opacity: 0.9
	});
	
	$("#quoteform .tb:input").tooltip({
		position: "bottom center",
		offset: [10, -50],
		effect: "fade",
		opacity: 0.9,
		tipClass: "tooltip1"
	});
	
	
	if ($(".transportdate").length )
	 	{
			// quote form transport dates
			
			$(".transportdate").dateinput({ trigger: true, format: 'dd mmmm yyyy', min: -1 })
		
			$(".transportdate:first").data("dateinput").change(function() 
				{
					$(".transportdate:last").data("dateinput").setMin(this.getValue(), true);
				});
			
			// end transport dates	
		}
	
	if ($(".storagedate").length )
	 	{
			// quote form storage dates
	
			$(".storagedate").dateinput({ trigger: true, format: 'dd mmmm yyyy', min: -1 })
		
			$(".storagedate:first").data("dateinput").change(function() 
				{
					$(".storagedate:last").data("dateinput").setMin(this.getValue(), true);
				});
			
			// end storage dates
		}
		
	if ($(".shippingdate").length )
	 	{
			// quote form shipping dates
	
			$(".shippingdate").dateinput({ trigger: true, format: 'dd mmmm yyyy', min: -1 })
		
			$(".shippingdate:first").data("dateinput").change(function() 
				{
					$(".shippingdate:last").data("dateinput").setMin(this.getValue(), true);
				});
			
			// end shipping dates
		}
	
	tinyMCE.init({
	// General options
	script_url : 'scripts/tiny_mce/tiny_mce.js',

	mode : "textareas",
	theme : "advanced",
	extended_valid_elements : "div[*]a[*]",
	forced_root_block : false,
    forced_root_block : false,
	force_p_newlines : false,

	plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",

	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,iespell,print,fullscreen, code",
	theme_advanced_buttons2 : "cut,copy,paste,|bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup|,insertdate,inserttime,preview,|,forecolor,backcolor",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "bottom",
	theme_advanced_resizing : true,

	// Example content CSS (should be your site CSS)
	content_css : "css/example.css",
	editor_deselector : "mceNoEditor",
	editor_deselector : /(NoEditor|NoRichText)/,

	// Drop lists for link/image/media/template dialogs
	template_external_list_url : "js/template_list.js",
	external_link_list_url : "js/link_list.js",
	external_image_list_url : "js/image_list.js",
	media_external_list_url : "js/media_list.js",

});
	
});
