// JavaScript Document
$(function(){
					 
	Aesthetics = new function(){
		
		this.bind = function(){ /** Add all trigger events here **/
		
			$('.refine-search').fancybox({
				frameWidth: 430,
				frameHeight: 250
		 	});
			
			$('input[name=member_email]').focus(function(){
		 		if($(this).attr('value') == 'Email Address') $(this).attr('value','');
		  });
			
			$('input[name=member_email]').blur(function(){
				if($(this).attr('value') == '') $(this).attr('value', 'Email Address');
			});
			
			$('.staff-search select').change(function(){
				$('form[name="staff-search"]').submit();
				return false;
			});
			
			$('#book-staff').submit(function(){
				var paramz = $(this).serialize();
				$.post("/favourites.php", $(this).serialize(), function(data){
					if(data == 'formSent'){
						$('#book-staff').html('* Thanks for requesting our staff at a future event.');
					} else $('#form-errors').html(data);
				});
				return false;
			});
		
			$('a.add-booking').click(function(){
				Aesthetics.addFavToForm($(this).attr('rel'), $(this).attr('title'));
				$(this).css('display','none');
				return false;
			});
			
			$(".date").datepicker();
			
			$('.remove-model').click(function(){
				Aesthetics.removeModel($(this));
				return false;
			});
		
			$("a.fancybox").fancybox({
				frameWidth: 776,
				padding: 1,
				hideOnContentClick: false,
				overlayColor: "#FFF"
			});
			
			$('a.uploadCv').fancybox({
				 frameWidth: 362,
				 frameHeight:173,
				 padding: 1,
				 hideOnContentClick: false,
				 overlayColor: "#FFF"
			});
		
			
			$(".menu li a img").hover(function(){
				Aesthetics.menuHover($(this));
			}, function(e){
				Aesthetics.menuHover($(this));
			});
			
			$('.client-logos img.link').hover(function(){
				var src = $(this).attr("src");
				var Update = Aesthetics.changeGif(src);
				//var Update = Aesthetics.changeJpg(src);
				$(this).attr('src', Update);
			});
			
			$('ul.menu li').mouseenter(function(e){
				var html = $('.'+$(e).attr('rel')).html();
				if(1==2){
					Aesthetics.dropMenu(html);
				}
			});
			
			$('ul.menu li').mouseleave(function(e){
				$('.drop-down').stop().animate({top: '-35px'});
			});
			
			$(".staff-links a, a.view-model").fancybox({
				frameWidth: 776,
				frameHeight: 400,
				padding: 1,
				hideOnContentClick: false,
				overlayColor: "#FFF"
			});
			/*
			$(".client-logos a").fancybox({
					frameWidth          : 776,
					padding             : 1,
					hideOnContentClick  : false,
					frameHeight         : 310,
					overlayColor        : "#FFF",
					callbackOnShow      : function(){
						$('.client-text').jScrollPane({showArrows:true, scrollbarWidth: 19, arrowSize: 13, dragMinHeight: 53, dragMaxHeight: 53 });
					}
			});
			*/
			
			Aesthetics.modelPaging();
		}
		
		this.addFavToForm = function(model_id, name){
			if(model_id.length > 0){
				if($('#event_model_'+model_id).length == 0){
					$('.selected-staff').append('<div class="selected_model" id="event_model_'+model_id+'"><span>'+name+'</span> <a href="" class="remove-event-model" rel="'+model_id+'" title="Remove '+name+'">Remove</a> <input type="hidden" name="event_staff[]" value="'+model_id+'" /></div>');
					//Aesthetics.bind();
					$('a.remove-event-model').click(function(){
						Aesthetics.removeEventModel($(this));
						return false;
					});
				}
			}
		}
		
		this.removeEventModel = function(obj){
			var modelObj = obj.parent().attr('id');
			modelObj = modelObj.replace('event_','');
			
			$('#'+modelObj+ ' a.add-booking').css('display','block');
			obj.parent().remove();
		}
		
		this.dropMenu = function(content){
			$('.drop-down').html(content);
			$('.drop-down').stop().animate({top: '20px'}, 800, 'easeOutBounce');
			//$('.drop-down').css('top', '20px');
		}
		
		this.modelPaging = function(){
			$('.model-paging a').click(function(){
				var href = $(this).attr('href');
				$('.staff-loader').load(href + ' .staff-holder',function(data){
					Aesthetics.modelPaging();
					$(".staff-links a").fancybox({
						frameWidth: 776,
						padding: 1,
						hideOnContentClick: false,
						overlayColor: "#FFF"
					});
				});
				return false;
			});		
		}
		
		this.menuHover = function(e){
			if(!$(e).hasClass("current")){
				var src = $(e).attr("src");
				var newSrc = Aesthetics.changeSrc(src);
				$(e).attr("src", newSrc);
			}			
		}
		
		this.changeSrc = function(img){
			var newSrc = img.replace('-off.png', '-on.png');
			if(newSrc == img){
				var newSrc = img.replace('-on.png', '-off.png');
			}
			return newSrc;
		}
		
		this.changeGif = function(img){
			var newSrc = img.replace('-off.', '-on.');
			if(newSrc == img){
				var newSrc = img.replace('-on.', '-off.');
			}
			return newSrc;
		}
		
		
		this.removeModel = function(obj){
			if(confirm('Are you sure you wish to remove this model?')){
				var id = obj.attr('rel');
				/*$('#model_'+id).stop().effect('fold',false,500,false);
				$('#model_'+id).remove();*/
				$.get('favourites.php?removeModel='+id, function(data){
				 $('#model_'+id).css('opacity','0.3');
			  });
			}
		}
		
		this.makeSlide = function(elem,width,height,offset,dir,next,prev){
			if($(elem) !== false){
				$(elem).slide({
					Width: width,
					Height: height,
					Offset: offset,
					Direction: dir,
					NextClass: next,
					PrevClass: prev,
					Speed: 300
				});
			}
		}
	}
	
	Aesthetics.bind();
	
	Aesthetics.makeSlide('.favourites', 188,286,4,'horizontal','fav-next','fav-prev');
	Aesthetics.makeSlide('#staff-slider', 120,20,5,'vertical','staffNext','staffPrev');
	Aesthetics.makeSlide('#specialist-slider', 120,20,5,'vertical','specialNext','specialPrev');
	Aesthetics.makeSlide('#event-support-slider', 120,20,5,'vertical','essNext','essPrev');
	Aesthetics.makeSlide('.slider-container', 745,175,1,'horizontal','right-controller','left-controller');
	
	if(window.location.pathname == '/testimonials/'){
		var first = $("#first");
		var second = $("#second");
		
		swapText = function(){
			if(first.attr("rel") == "1"){
				first.fadeOut(2000).attr("rel", "0");
				second.fadeIn(2000).attr("rel", "1");
			} else {
				first.fadeIn(2000).attr("rel", "1");
				second.fadeOut(2000).attr("rel", "0");
			}
		}
		
		setInterval(swapText, 8000);
	}
	
});
