$(function(){
	
	var site = function() {
		this.bannerA = $('#banner a.banner-button');
		this.contactSlider = $('#button-contact');
		this.service = $('a#button-service');
		this.plugin = $('#button-plugin');
		
		this.podcasts = $('#podcasts');
		this.podcastHeader = this.podcasts.find('.podcast-header');
		this.podcastBody = this.podcasts.find('.podcast-body');
		
		this.readingOptions = $('ul#post-reading-options');
		this.respond = $('#respond');
		
		this.slides = $('#banner-main').find('img');
		
		//Run
		this.init();
	};

	site.prototype = {
			
		init : function(){
			this.setSlideFade(this.service, 'h3', 'intent');
			this.setSlideFade(this.plugin, 'img', 'intent');
			
			this.setContactSlider(this.contactSlider);
			this.setAccordion(this.podcastHeader, this.podcastBody);
			
			this.setSlideshow(this.slides);
			
			this.setReadingOptions(this.readingOptions);
			
			//Banner Buttons
			this.setSlider(this.bannerA, 'span.slider');
		},
		
		setAccordion: function(header, body){
			header.css('cursor', 'pointer'); //Initial CSS
			body.not(body.eq(body.length-1)).slideUp(); //Leave the latest (last) one open
			
			header.click(function(){
				if($(this).next().is(':visible')){
					$(this).next().slideUp();
				}else {
					header.next().slideUp();
					$(this).next().slideDown();
				}
			});
		},
		
		setReadingOptions: function(readingOpts){			
			var colOpt = readingOpts.find('li a');
			var postBody = readingOpts.siblings('.post-body');
			
			colOpt.click(function(e){
				e.preventDefault();
				var setCol = $(this).attr('id');
				var speed = 'medium';
				
				//Add New Format
				postBody
				.fadeOut(speed, function(){
					//Remove Any Other Formats
					colOpt.each(function(){
						postBody.removeClass($(this).attr('id'));
					});
					postBody.addClass(setCol);
				})
				.fadeIn(speed);
				
			});
		},
		
		//endables the slidedown meu. and adds support for IE6
		setSlider : function(menu, find){
			var speedIn = 300;
			var speedOut = 500;
			
			menu.find(find).hide();
			
			menu.hover(function(){
				//mouseover
				$(this).find(find).stop(true, true).slideDown(speedIn);
			}, function(){
				//mouseout
				$(find).stop(true, true).slideUp(speedOut);		
			});
		},
		
		//custom over
		setContactSlider: function(button){
			var speed = 250;
			button.find('span#contact-top').css('background-position', '-60px 0px');
			
			button.hover(function(){
				//mouseover
				$(this).find('span#contact-top').stop(true, true).animate({'background-position':'56px 0px'}, speed);
			}, function(){
				//mouseout
				$(this).find('span#contact-top').stop(true, true).animate({'background-position': '-60px 0px'}, speed);
			});
		},
		
		//enable slide menu - slide in and fade out
		setSlideFade: function(button, find, intent){
			var speed = 150;
			
			button.find(find).css('display', 'none');
			
			if(intent == 'intent') {
				button.hoverIntent(function(){
					//mouseover
					$(this).find(find).stop(true, true).slideDown(speed);
				}, function(){
					//mouseout
					$(this).find(find).stop(true, true).fadeOut(speed);		
				});
				
			}else{
				button.hover(function(){
					//mouseover
					$(this).find(find).stop(true, true).slideDown(speed);
				}, function(){
					//mouseout
					$(this).find(find).stop(true, true).fadeOut(speed);		
				});
			}//intent if
		},
		
		setSlideshow : function(images, speed, interval) {
			var index = 0;
			var slides = images;
			if (speed == null){ speed = 600; }
			if (interval == null) { interval = 8000; }
			if (slides.length > 1) {
			//Instantiate
			setInterval(sift, interval);
				//Controler
					function sift(x)
						{
							if(index<(slides.length-1)){index+=1;}
							else {index=0;}
							show(index);
						}
				//CORE
					function show(num)
						{
							$(slides).fadeOut(speed, function(){
								$(slides[num]).fadeIn(speed);
							});
							
						}
				//Instantiate
					$(slides).hide();
					show(index);
			}//end if > 1 slide
		}
		
	};
	
	//run
	new site();
	
	
	
});

