(function($){
	
	/*  Custom made plugin for Folke Rydén
		Author: Hjalmar Hägglund - http://punc.se
	*/
	
	$.fn.scroll = function(options) {

		
		return this.each(function() {
			var opts = $.extend(true, {}, $.fn.scroll.defaults, options)

			var up = $('<div class="scrollup" />').css({
				position: "absolute",
				right: 0,
				top: 0,
				cursor: "pointer"
			});

			var down = $('<div class="scrolldown" />').css({
				position: "absolute",
				right: 0,
				bottom: 0,
				cursor: "pointer"

			});

			var wrap = $('<div class="dropwrap" />').css({
				position: "absolute",
				padding: 0,
				margin: 0,
				top: 38,
				left: 0,
				height: opts.height,
				zIndex: 9
			});

			var handle = $('<div class="handle" />').css({
				position: "absolute",
				top: 35,
				right: 0,
				height: 20,
				width: 10,
				opacity: 0.3,
				background: "#000"
			})
			
			var $elem = $(this);



			var $drop = $("ul", $elem).css({
				height: opts.height-70,
				margin: "35px 0",
				overflow: "hidden"
			});

			$drop.wrap($(wrap).clone());

			var $wrap = $(".dropwrap", $elem).hide();

			var barheight = $wrap.outerHeight()-70;



			$wrap.css({
				overflow: "hidden"
			}).append(up.clone()).append(down.clone()).append($(handle).clone()

				.css({
					height: barheight
				})


			);

			var scrollstep,
				scrollheight,
				handlestep,
				handlestep;


			$("a.chose", $elem).click(function() {
				$(this).toggleClass("open");
				$wrap.slideToggle(500, function() {
					
					
					scrollheight = $drop[0].scrollHeight;
					scrollstep = ($drop.innerHeight())/scrollheight;
					handlestep = ($drop.innerHeight())*scrollstep;

			
					$(".handle", $elem).animate({
						top: 35,
						height: handlestep
					});
					
				});

				return false;
			})

			$(".scrollup, .scrolldown", $elem).hover(function() {
				$(this).fadeTo(400,1);
			},function() {
				$(this).fadeTo(400,.7);
			});

			$(".scrollup", $elem).css("opacity", .7).click(function() {
				$drop.animate({
					scrollTop: $drop.scrollTop()-$drop.innerHeight()
				}, 500, "swing", function() {
					
				})
				$(".handle", $elem).animate({
					top: [35 <= parseInt($(".handle", $elem).css("top"))-handlestep ? parseInt($(".handle", $elem).css("top"))-handlestep : 35]
				})
				return false;


			})

			$(".scrolldown", $elem).css("opacity", .7).click(function() {
				$drop.animate({
					scrollTop: $drop.scrollTop()+$drop.innerHeight()
				}, 500, "swing", function() {
					

				})
				$(".handle", $elem).animate({
					top: [(opts.height-35-handlestep) >= parseInt($(".handle", $elem).css("top"))+handlestep ? parseInt($(".handle", $elem).css("top"))+handlestep : (opts.height-35-handlestep)]
				})
				return false;

			})


		});
	}

	$.fn.scroll.defaults = {
		height: 300
	}
})(jQuery);

(function($){
	
	/*
	Placeholder plugin for jQuery, made to mimic Safari's placeholder.
	
	Usage:
		* Use attribute placeholder="type here" in html (html5 valid)
		* 
		* default:
			$(element).placeholder();
		* or with custom options:
		 	$(element).placeholder({
				phtext: {
					fontStyle: "italic"
				},
				ttext: {
					fontStyle: "normal"
				}
			});
		
		* options:
			phtext: { // css styles for placeholder text
				color: "#aaa"
			},
			ttext: { // css styles for typed text
				color: "#000"
			},
			force: false // force browsers with placeholder functionality to use the plugin anyway. (ie if you ar using custom styling)
	
	Written by Hjalmar Hägglund - Punc AB - hjalle at punc dot se, http://punc.se
	
	May be used and rewritten freely, but I'd love to know where it's beeing used, so please send me an email.
	
	*/
	$.fn.placeholder = function(options) {
		var opts = $.extend(true, {}, $.fn.placeholder.defaults, options);
		if(supports_input_placeholder() && !opts.force) {
			return;
		}
		return this.each(function() {
			//if($(this).is("[placeholder]")) {
				var $this = $(this);
				
				var holdertext = $(this).attr("title");
				
				$(this)
				.css(opts.phtext)
				.val(holdertext)
				
				.focus(function() {
					if($(this).val()==holdertext) {
						$(this)
						.css(opts.ttext)
						.val("");
					}
				})
				.blur(function() {
					if($(this).val()=="") {
						$(this)
						.css(opts.phtext)
						.val(holdertext);
					}
				})
				.parents("form").submit(function() {
					if($this.val()==holdertext) {
						$this.val("");
					}
				});
			//}
		});
	}
	
	$.fn.placeholder.defaults = {
		phtext: {
			color: "#aaa"
		},
		ttext: {
			color: "#000"
		},
		force: false
	}
	
})(jQuery);

//function to look for placeholder support
function supports_input_placeholder() {
  var i = document.createElement('input');
  return 'placeholder' in i;
}

(function($) {
	$.fn.blocklink = function(options) {
		
		/*  Custom made plugin for Folke Rydén
			Author: Hjalmar Hägglund - http://punc.se
		*/
		
		var opts = $.extend(true, {}, $.fn.blocklink.defaults, options);
		
		return this.each(function() {
			var anchor = $("a", this)[0];
			opts.over.color = $(anchor).css("color");
			opts.out.color = $(this).css("color");
			opts.over.cursor = "pointer";

			$(this).hover(function() {
				$(this).css(opts.over)
			}, function() {
				$(this).css(opts.out)
			});
			
			$(this).click(function() {
				window.document.location = anchor.href;
			});
			
			})
	}
	
	$.fn.blocklink.defaults = {
		over: {
			"text-decoration": "underline"
		},
		out: {
			"text-decoration": "none"
		}
	}
	
})(jQuery);

jQuery(document).ready(function(){
	jQuery("#s").placeholder({
		force: true,
		phtext: {
			fontStyle: "italic"
		},
		ttext: {
			fontStyle: "normal"
		}
	})
	jQuery(".dropdown").scroll({
		height: 316
	});
	
	jQuery("#news_listing .post").blocklink();
	
  // Dropdown menu
  
  jQuery('#mainnav li').hover(function(){
    jQuery('ul:first',this).css('display', 'block');
    
  },function(){
    jQuery('ul:first',this).css('display', 'none');
    
  });
  
});
