$(document).ready(function(){
						   
	
	/*************************************************************
								IMAGE PRELOAD	
	/************************************************************/
	
	// Preload images
	/*
	$.preload([
			"http://little-seal.co.uk/dev/dev12/images/intro_little_seal_txt.gif",
			"http://little-seal.co.uk/dev/dev12/images/little_sea_bg.jpg",
			"http://little-seal.co.uk/dev/dev12/images/lintro_seal.png"
			
		], {
			init: function(loaded, total) {
				//$('#seal').css("opacity", 0);
				$('#font').css("opacity", 0);
				
			},
			loaded: function(img, loaded, total) {

			},
			loaded_all: function(loaded, total) {
				
				//$('#seal').animate({opacity:1},900, function(){ $('#font').animate({opacity:1},2000);});
				$('#font').animate({opacity:1},2000);
				setTimeout(function(){
						 $('#content').slideDown(1500,'backout').animate({opacity:1},300);
						 carousel_init();
						 }, 600);
				
			}
	});
	*/
	
	
	

	/*************************************************************
						BROWSER CHECK	
	/************************************************************/
	
	var safari = $.browser_detect('safari');
	var firefox = $.browser_detect('firefox');
	var firefox3 = $.browser_detect('firefox',3);
	var chrome = $.browser_detect('chrome');
	var ie = $.browser_detect('ie');
	var ie6 = $.browser_detect('ie',6);
	var ie7 = $.browser_detect('ie',7);
	var ie8 = $.browser_detect('ie',8);
	
	//	 set styles for different browsers
	
	// Add hover class to drop down menu
	if(ie6){
		$('#main-nav ul li').hover(function(){
											$(this).addClass('hover');
									},
									function(){
										$(this).removeClass('hover');
									}
					);
	}

	/*************************************************************
							NEW WINDOW	
	/************************************************************/
	
	//	Open new window on clicking link
	$.new_window();
	
	if($("#paypal_donation_form").length>0){
		$("#paypal_donation_form").attr({"target": "_blank"});
	}
	
	
	/*************************************************************
							SCROLL TO TOP	
	/************************************************************/
	
	$('#to_top').click(
					   
				function(){
						to_top('#top');
						return false;
	});
	
	
	
	
	
	/*************************************************************
						RETURN TO HOME PAGE	
	/************************************************************/
	
	//	Create header link back to home page
	$('header, nav_main').css({cursor:'pointer'}).click(function(){location.href = 'http://stonewriters.co.uk';});
	$('#mask').show().fadeOut(2000);
	
	
	/*************************************************************
								TOOLTIP	
	/************************************************************/
	
	// Add opacity property not validating in CSS2.1
	if($('.tooltip').length!=0){
		
		$('#tooltip').css({opacity: 0.85});
	
		// Insert email for tooltip
		$('a.tooltip_email').attr({title:' - '+emailE });
		
		// Tooltip
		$('.tooltip').tooltip({ 
							  
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 250 
		
		});
	}
	
	/*************************************************************
							SCROLLING DIV	
	/************************************************************/
	
	var $scrollingDiv = $(".scroll_div");
	var maxScroll =  ($scrollingDiv.parent().outerHeight(true)) - ($scrollingDiv.outerHeight(true)/2) - (90); 
	
	$(window).scroll(function(){

		if($(window).scrollTop() > 350 && $(window).scrollTop() <= maxScroll ){ // Start scrolling after this distance from the top - adjust it for what you need (trial and error or a ruler on the screen graduated in pixels  )
		
			// If the scrolling div has reached the bottom stop scrolling
			$scrollingDiv
			.stop()
			.animate({"marginTop": ($(window).scrollTop() - 350 ) + "px"}, "slow" ); // How many pixels to add to the distance
			
		}

		else if($(window).scrollTop() <= 250 ){ // Less than this distance = RESET to original margin - set to 0 here but you can reset to your own original margin - this stops the element raising up too high up the page
			$scrollingDiv
			.stop()
			.animate({"marginTop": "0px"}, "slow" );
		}

});
	


	/*************************************************************
							NAV BUTTON FADE EFFECT	
	/************************************************************/
	// OPACITY OF BUTTON SET TO 100%
		var nav_links = $("#nav_1 li.nav_links a");
		nav_links.css({"opacity":"1.0"});
		
		
		// ON MOUSE OVER
		nav_links.hover(function () {
										  
			var orig_class = $(this).parent('li').attr('id');
			
			if(!$(this).hasClass('selected')){
				// Change class
				$(this).removeClass(orig_class);
											  
				// SET OPACITY TO 30%
				$(this).stop().css({"opacity":"0.3"})
				.animate({
					opacity: 0.3
				}, 300, function(){
					$(this).addClass(orig_class)				
					.animate({
						opacity: 1 // Opacity of of mouseover
					}, 500);
				});
			}
			
			
		},
		
		// ON MOUSE OUT
		function () {
			
			var orig_class = $(this).parent('li').attr('id');
			
			if(!$(this).hasClass('selected')){
				
				$(this).addClass('selected').stop()
				.css("opacity",1) // Opacity of of mouseover
				.animate({
					opacity: 0.3 
				}, 300, 
				
				function(){
					
					var this_class = $(this).hasClass(orig_class);
				
					if(!$(this).hasClass(orig_class)){
						$(this).addClass(orig_class);
					}
					
					$(this).removeClass('selected');
					// SET OPACITY BACK TO 100%
					$(this)
					.animate({
						opacity: 1.0
					}, 500);
				});
			}
		});
		
	
		
	/*************************************************************
							ACCORDION
	/************************************************************/
	/*
	var selected_item = $('#nav_2 ul li a.selected');
	var accord_parent = selected_item.parent().parent().parent().hasClass('li_parent');
	
	if(accord_parent)
	{
		var li_parent = selected_item.parent().parent().parent().get(0);
		var parent_id = $(li_parent).attr('id');
		$('#menu_left').accordion({expandSub : true, initShow : '#'+parent_id});
	}
	else
	{
		$('#menu_left').accordion({expandSub : true});
	}
	
*/



	$.extend($.ui.accordion.animations, {
		fastslide: function(options) {
			 this.slide(options, { 
				easing: options.down ? "easeOutBack" : "swing", 
				duration: options.down ? 1000 : 400 
				}); 
			 }
		
	 });
	
	$.extend($.ui.accordion.animations, {
		smoothslide: function(options) {
			 this.slide(options, { 
				easing: options.down ? "swing" : "swing", 
				duration: options.down ? 1000 : 400 
				}); 
			 }
	});
	
	$.extend($.ui.accordion.animations, {
		bounce: function(options) {
			 this.slide(options, { 
				easing: options.down ? "easeOutBack" : "swing", 
				duration: options.down ? 1500 : 1000 
				}); 
			 }
	});
	
	//	Check which left menu header is active
	
	var selected_item = $('#nav_2 ul li a.selected');
	var accord_parent = selected_item.parent().parent().parent().hasClass('li_parent');
	
	if(accord_parent)
	{
		var li_parent = selected_item.parent().parent().parent().get(0);
		var active_but = $(li_parent).find('a');
	}
	else
	{
		var active_but = '';
	}

//	Activate accordion on chosen lists
	$( "#menu_left" ).accordion({
							   active: active_but,
							   alwaysOpen: false,
							   autoheight: false,
							   animated: 'bounce',
							   header: 'a.no_link'
							   
						
	});

	/*
	setTimeout(function(){
						$(active_but).click();
						}, 1500);
	*/
	
	$("ul li ul li:last-child").each(function(index) { $(this).addClass("last-item"); });
	

						   
});

/*
*
*	Functions
*
*/
function over(event){$(this).find('a').css({'color':'#F30'});}
function out(event){$(this).find('a').css({'color':'#999'});}
function to_top(el){var target_offset=$(el).offset();var target_top=target_offset.top;$('html, body').animate({scrollTop:target_top},500);}
function nav(el,href){$(el).addClass("hidden");location.href=href;}
(function($){$.browser_detect=function(){var userAgent=navigator.userAgent.toLowerCase();$.browser.chrome=/chrome/.test(navigator.userAgent.toLowerCase());if($.browser.msie){$('body').addClass('ie '+$.browser.version.substring(0,1));}
if($.browser.chrome){userAgent=userAgent.substring(userAgent.indexOf('chrome/')+7);userAgent=userAgent.substring(0,1);$('body').addClass('chrome '+userAgent);$.browser.safari=false;}
if($.browser.safari){userAgent=userAgent.substring(userAgent.indexOf('version/')+8)
userAgent=userAgent.substring(0,1);$('body').addClass('safari '+userAgent);}
if($.browser.mozilla){if(navigator.userAgent.toLowerCase().indexOf('firefox')!=-1){userAgent=userAgent.substring(userAgent.indexOf('firefox/')+8);userAgent=userAgent.substring(0,1);$('body').addClass('firefox '+userAgent);}
else{$('body').addClass('mozilla ');}}
if($.browser.opera){$('body').addClass('opera ');}
var argLgth=arguments.length;if(argLgth==1){var browser=arguments[0];ver=false;var arg=false;}
else if(argLgth==2){var browser=arguments[0];var ver=arguments[1];var arg=true;}
var body_class=$('body').attr('class');var browserTest=body_class.indexOf(browser);if(arg){var version=body_class.indexOf(ver);}
if(browserTest>=0){if(arg){if(version>=0){return true;}
else{return false;}}
else{return true;}}
else{return false;}};})(jQuery);(function($){var imgList=[];$.extend({preload:function(imgArr,option){var setting=$.extend({init:function(loaded,total,animate){},loaded:function(img,loaded,total){},loaded_all:function(loaded,total,animate){},preloadClass:'preload_img'},option);var total=imgArr.length;var loaded=0;var animated=setting.animated;var cacheObj=$("<img />");setting.init(0,total);for(var i in imgArr){imgList.push(cacheObj.attr({src:imgArr[i]}).load(function(){loaded++;setting.loaded(this,loaded,total);if(loaded==total){setting.loaded_all(loaded,total);}}));}}});})(jQuery);(function($){$.new_window=function(){$('a.new_window').click(function(){window.open(this.href,"smallwin","width=800,height=600,top=200,left=200,toolbar=0,menubar=0,resizable=yes,scrollbars=yes");return false;});}})(jQuery);
