// Rotator
function theRotator(rotator,timing) {
	//Set the opacity of all images to 0
	//$(rotator+'>ul>li').css({opacity: 0.0});
	$(rotator+'>ul>li').hide();
	//Get the first image and display it (gets set to full opacity)
	//$(rotator+'>ul>li:first').css({opacity: 1.0});
	$(rotator+'>ul>li:first').show();
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval(function () {	
	//Get the first image
	var current = ($(rotator+'>ul>li.show')?  $(rotator+'>ul>li.show') : $(rotator+'>ul>li:first'));
	if ( current.length == 0 ) current = $(rotator+'>ul>li:first');
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $(rotator+'>ul>li:first') :current.next()) : $(rotator+'>ul>li:first'));
	//Set the fade in effect for the next image, the show class has higher z-index
	next.hide().addClass('show').stop().show();
	//Hide the current image //,{queue:false}
	current.hide().removeClass('show');
	},timing);
}

function closeForm(){
	var name = $("#contact_name").val();
	var phone = $("#contact_phone").val(); 
	var email = $("#contact_email").val();
	var message = $("#contact_message").val();
	var subscribe = $("#contact_subscribe").val();
	if ($('#contact_subscribe').is(':checked')){subscribe = 'Yes';}else{subscribe = 'No';}
	var dataString = 'name=' + name + '&phone=' + phone + '&email=' + email + '&message=' + message + '&subscribe=' + subscribe;
	if(name=='' || phone=='' || email=='' || message==''){
		$('#messageSent').hide();
		$('#messageError').show();
	}else{
	  	 $.ajax({
    		type: "post",
    		url: "http://24hour-emergency-dentist.co.uk/email.php",
			/// fix the email
    		data: dataString,
    		success: function(){
    			$('#messageSent').show();
    			$('#messageError').hide();
    			setTimeout('$("#messageSent").hide();$("#contact-form-box").fadeOut(300)', 1500);
    			$('#contact_name').val('');
    			$('#contact_phone').val('');
    			$('#contact_email').val('');
    			$('#contact_message').val('');    	
		  	}
		});
	}
	return false;
}
$(document).ready(function() {
		if($.cookie('TEXT_SIZE')) {
			$('.content').addClass($.cookie('TEXT_SIZE'));	
		}
		$('.resizer a').click(function() {
			var textSize = $(this).parent().attr('class');
			$('.content').removeClass('small medium large').addClass(textSize);
			$.cookie('TEXT_SIZE',textSize, { path: '/', expires: 10000 });
			return false;
	});
	// Disable right click on img
	$("img").bind("contextmenu",function(e){return false;}); 
	// Disable drag on img
	$('img').bind('dragstart', function(event) { event.preventDefault(); });
	//$('a').bind('dragstart', function(event) { event.preventDefault(); });
	// Side menu
	$(".side-menu>li>ul").accordion({accordion:true,speed: 0,closedSign: '+',openedSign: '-'});
	// Load Tabs
	$(".tabs").tabs(".panes>div");
	//Load the slideshow
	theRotator(".rotator",8000);
	theRotator("#side_offer",8000);
/*	
	$('#header_slider').anythingSlider({
	// Appearance
	width               : null,      // Override the default CSS width
	height              : null,      // Override the default CSS height
	resizeContents      : true,      // If true, solitary images/objects in the panel will expand to fit the viewport
	navigationSize      : 16,     // Set this to the maximum number of visible navigation tabs; false to disable	
	onSlideComplete: function(slider) {
	// keep the current navigation tab in view
	slider.navWindow( slider.currentPage );
	},	
	// Navigation
	startPanel          : 1,         // This sets the initial panel
	hashTags            : false,      // Should links change the hashtag in the URL?
	buildArrows         : false,      // If true, builds the forwards and backwards buttons
	buildNavigation     : true,      // If true, buildsa list of anchor links to link to each panel
	navigationFormatter : null,      // Details at the top of the file on this use (advanced use)
	forwardText         : "&raquo;", // Link text used to move the slider forward (hidden by CSS, replaced with arrow image)
	backText            : "&laquo;", // Link text used to move the slider back (hidden by CSS, replace with arrow image)	
	// Slideshow options
	autoPlay            : true,      // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
	startStopped        : false,     // If autoPlay is on, this can force it to start stopped
	pauseOnHover        : false,      // If true & the slideshow is active, the slideshow will pause on hover
	resumeOnVideoEnd    : true,      // If true & the slideshow is active & a youtube video is playing, it will pause the autoplay until the video has completed
	stopAtEnd           : false,     // If true & the slideshow is active, the slideshow will stop on the last page
	playRtl             : false,     // If true, the slideshow will move right-to-left
	startText           : " ",   // Start button text
	stopText            : " ",    // Stop button text
	delay               : 8000,      // How long between slideshow transitions in AutoPlay mode (in milliseconds)
	animationTime       : 300,       // How long the slideshow transition takes (in milliseconds)
	easing              : "swing"    // Anything other than "linear" or "swing" requires the easing plugin
	});	
	*/
	///////EMAIL BOX
	$('#contact-form-box').hide();
	$('#contact-box').click(function() {
		$('#contact-box-holder #contact-form-box').fadeToggle(300);
	});		
	/////// SIDE BAR WIDGET
	$('#sidebar-left>.widget>h2').click(function(){
	  	if($(this).next().is(':hidden') != true){
			$(this).removeClass('active'); 
			$(this).css('background-position', 'left center');
			$(this).next().slideUp(300);
		}else{
			$('#sidebar-left>.widget>h2').removeClass('active');  
			$('#sidebar-left>.widget>h2').css('background-position', 'left center');
			$('#sidebar-left>.widget>ul').slideUp(300);		  
			if($(this).next().is(':hidden') == true){
				$(this).addClass('active');
				$(this).css('background-position', 'right center');
				$(this).next().slideDown(300);
			}
		}
	 });
});

