/********************************************* 
		JavaScript Document 
		Web Design and Development by:

		www.Developer7.com
		contact email:
		info@developer7.com

*********************************************/
$(document).ready(function() {
		
		$('.delete_button').click(function() {
			return confirm("Are you sure you want to delete?");
		});
			
		$('.global_message').delay(5000).fadeOut();
		
		$('.admin_open').toggle(function() {
			$(this).html('<img src="/img/icons/toggle_closed.png" />');
		}, function() {
			$(this).html('<img src="/img/icons/toggle_open.png" />');
		});
	
		$('#admin_edit').hide();
		$('.admin_open').click(function () {
			$('#admin_edit').slideToggle();	
				return false;
		});

		$('.edit, a.add_news, a.add_events').hide();
		$('.featured, .release, .event').mouseenter(function(){			
			$(this).children('.edit').fadeIn();															 
		});
		$('.featured, .release, .event').mouseleave(function(){											 
			$(this).children('.edit').fadeOut();				
		});

		$('.content').mouseenter(function(){			
			$('a.add_news, a.add_events').fadeIn();															 
		});
		$('.content').mouseleave(function(){											 
			$('a.add_news, a.add_events').fadeOut();				
		});
		
		$('.adminedit').hide();
		$(".posts").mouseenter(function(){			
				$(this).children('.adminedit').fadeIn('fast');															 
		});
		$(".posts").mouseleave(function(){											 
				$(this).children('.adminedit').fadeOut('fast');				
		});
		
		$(".full_posts").mouseenter(function(){			
				$(this).children('.adminedit').fadeIn('fast');															 
		});
		$(".full_posts").mouseleave(function(){											 
				$(this).children('.adminedit').fadeOut('fast');				
		});	
	
		$('.admincatedit').hide();
		$(".cattitle").mouseenter(function(){			
				$(this).children('.admincatedit').fadeIn('fast');															 
		});
		$(".cattitle").mouseleave(function(){											 
				$(this).children('.admincatedit').fadeOut('fast');				
		});
	
		$('.admincommentedit').hide();
		$(".full_comments").mouseenter(function(){			
				$(this).children('.admincommentedit').fadeIn('fast');															 
		});
		$(".full_comments").mouseleave(function(){											 
				$(this).children('.admincommentedit').fadeOut('fast');				
		});
		
		$('.edit_blog_cat, .delete_blog_cat, .handle').hide();
		$("ul.BlogNav li").mouseenter(function(){			
				$(this).children('a.edit_blog_cat, a.delete_blog_cat, .handle').fadeIn('fast');															 
		});
		$("ul.BlogNav li").mouseleave(function(){											 
				$(this).children('a.edit_blog_cat, a.delete_blog_cat, .handle').fadeOut('fast');				
		});	
		
		$('#contact_reason_list').hide();		
		$('.list_reason').click(function(){
				if ($('#contact_reason_list').is(':visible')) { 
				 $('#contact_reason_list').fadeOut('fast');
				 $('a.list_reason').removeClass('active');
			 }else if ($('#contact_reason_list').is(':hidden')){
				 $('#contact_reason_list').fadeIn('fast');
				 $('a.list_reason').addClass('active');
				}	
				return false;
		});

		// Login
		$('.login').fancybox({
			'type'			: 'iframe',	
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,			
			'height'		:	280,
			'width'		:	520,
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'modal'   : true
		});		

		// Create user
		$('.create_user').fancybox({
			'type'			: 'iframe',	
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,			
			'height'		:	420,
			'width'		:	680,
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'modal'   : true
		});	

		// Change password
		$('.change_password').fancybox({
			'type'			: 'iframe',	
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,			
			'height'		:	365,
			'width'		:	353,
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'modal'   : true
		});	

		// Add page content
		$('.add_page_content, .edit_page_article, .add_news, .edit_news, .add_events, .edit_event').fancybox({
			'type'			: 'iframe',	
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,			
			'height'		:	'100%',
			'width'		:	'100%',
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'modal'   : false,
			'onClosed': function() { parent.location.reload(true); }
		});	

		// Add single field box
		$(".add_blog_cat, .edit_blog_cat").fancybox({
			'type'			: 'iframe',
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,			
			'autoDimensions' : true,
			'autoScale' : true,
			'height' : 175,
			'width' : 430,
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'modal'   : true
		});	
		
		// Add page content
		$('.sort_navigation').fancybox({
			'type'			: 'ajax',	
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,			
			'padding'			:    10,
			'autoDimensions' : true,
			'autoScale' : true,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'modal'   : false,
			'onClosed': function() { parent.location.reload(true); }
		});

		// Login
		$('.add_contact_reason, .edit_contact_reason').fancybox({
			'type'			: 'iframe',
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,			
			'autoDimensions' : true,
			'autoScale' : true,
			'height' : 175,
			'width' : 430,
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'modal'   : true
		});	
				
		// Add page content
		$('.add_page, .edit_page').fancybox({
			'type'			: 'iframe',
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,
			'height'		:	480,
			'width'		:	570,
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'onClosed': function() { parent.location.reload(true); } 
		});	
		
		// Add edit site info
		$('.edit_info').fancybox({
			'type'			: 'iframe',														
			'height'		:	480,
			'width'		:	370,
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'onClosed': function() { parent.location.reload(true); } 
		});
	
		// Add edit site info
		$('.contact_reason').fancybox({
			'type'			: 'iframe',														
			'height'		:	350,
			'width'		:	520,
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,
			'padding'			:    10,
			'hideOnContentClick': false,
			'hideOnOverlayClick': false,
			'scrolling' : 'no',
			'titleShow'  : false,
			'onClosed': function() { parent.location.reload(true); } 
		});	
		
		// Single image
		$('a.single_image').fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack',
			'titlePosition' :	'over',
			'overlayShow'	:	false								 								 
		});
	
		// Grouped image by rel="group1"
		$('a.gallery').fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack',
			'titleShow' :	false,
			'overlayShow'	:	false
		});		
		
		// Modal
		$('#modal').fancybox({
			'type'			: 'inline',														
			'autoDeminsion'		:	true,
			'autoScale'		:	true,
			'transitionIn'	:	'fade',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200,
			'padding'			:    0,
			'titleShow'  : false
		});			
		
		$('.contactinput, .contactemailinput, select, .contacttextarea, .scheduleinput, .pickuptextarea').focus(function(){
				$(this).css({border: '2px solid #5DAFD7'});		
		});
		
		$('.contactinput, .contactemailinput, select, .contacttextarea, .scheduleinput, .pickuptextarea').blur(function(){
				$(this).css({border: '2px solid #cccccc'});		
		});			

		$("#start_date, #end_date, #date").datepicker({ dateFormat: 'yy-mm-dd' });
		
		$("a.anchorLink").anchorAnimate();
		
		
		///////////////////////////// start blog functions ///////////////////////////////////
		$("#comments_form").submit(function() {
			var comment_author = $("#comment_author").val(); 
			var email = $("#email").val(); 
			var comment_body = $("#comment_body").val(); 
			var ip = $("#ip").val(); 
			var post_id = $("#post_id").val(); 
			var comment_date = $("#comment_date").val(); 
			var comment_status = $("#comment_status").val(); 
			$.post("/blog/comment", { 
				 comment_author:comment_author, 
				 email:email, 
				 comment_body:comment_body, 
				 ip:ip, 
				 post_id:post_id, 
				 comment_date:comment_date, 
				 comment_status:comment_status 
				},function(data){
					$("#comment_author_error").html(data.comment_author);
					$("#email_error").html(data.email);
					$("#comment_body_error").html(data.comment_body);				
					if(data.success == true){					
							$('#comments_form').fadeOut(1000, function() {
									$('.commentform').html('<h2>Your comment was sent succesfully!</h2>');														
								});
					}					
				},'json');
				return false;
		});	
		
		
	$('.BlogNav').sortable({
					opacity: '0.5',
					handle: '.handle',
					update: function(e, ui){
							order = $(this).sortable("serialize");
							$.ajax({
											url: "/blog/process_sortable_categories/",
											type: "POST",
											data: order,
											success: function(data){
												
											}
											},'json');
									}
			});		
		///////////////////////////// start custom functions ///////////////////////////////////

		$("#schedule_pickup").submit(function() {																	
				var fname = $("#fname").val(); 
				var lname = $("#lname").val(); 
				var pnumber = $("#pnumber").val(); 
				var email = $("#email").val(); 
				var date = $("#date").val(); 
				var times = $("#times").val(); 
				var company = $("#company").val(); 
				var address = $("#address").val(); 
				var comments = $("#comments").val(); 
				var ip = $("#ip").val(); 
				$.post("/ajax/schedule_pickup", { 
																	fname:fname, 
																	lname:lname, 
																	pnumber:pnumber, 
																	email:email, 
																	date:date, 
																	times:times, 
																	company:company, 
																	address:address, 
																	comments:comments, 
																	ip:ip 
																	},
				function(data){
					$("#fname_error").html(data.fname);
					$("#lname_error").html(data.lname);
					$("#pnumber_error").html(data.pnumber);
					$("#email_error").html(data.email);
					$("#date_error").html(data.date);
					$("#times_error").html(data.times);
					$("#address_error").html(data.address);
					$("#ip_error").html(data.ip);
					
						if(data.success == true){
							
							$('#schedule_pickup').fadeOut(1000, function() {
									$('#schedule_pickup_message').html(data.message);														
								});
							}	
					
				},'json');
				return false;
		});

		
		
	
 }); // end functions
	
	// Begin Animated Scroll
	jQuery.fn.anchorAnimate = function(settings) {
		settings = jQuery.extend({
		speed : 1100
		}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
			return false;
			})
		});
	} ///////// end animated anchors /////////
	

