// JavaScript Document

/* ===============================================
  Roll over
=============================================== */
	function initRollOverImages(){
		var image_cache = new Object();
		$("img.rover,input.rover").each(function(i){
			var imgsrc = this.src;
			var dot = this.src.lastIndexOf('.');
			var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
			image_cache[this.src] = new Image();
			image_cache[this.src].src = imgsrc_ro;
			$(this).hover(function(){
				this.src = imgsrc_ro;
			},function(){
				this.src = imgsrc;
			});
		});
	}

/* ===============================================
  Menu active
=============================================== */
	function Menu_active(id){
		if(id != ''){
			var target_img = "img#"+id;
			$(target_img).each(function(i){
				dot = this.src.lastIndexOf('.');
				var imgsrc_ro = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
				this.src = imgsrc_ro;

				$(this).hover(function(){
					this.src = imgsrc_ro;
				},function(){
					this.src = imgsrc_ro;
				});
			});
		}
	}

/* ===============================================
  Menu active (text)
=============================================== */
	function localMenu_active(id){
		if(id != ''){
			var target_img = "li#"+id;
			$(target_img).each(function(i){
				$(this).addClass("on");
			});
			var target_img = "dd#"+id;
			$(target_img).each(function(i){
				$(this).addClass("on");
			});
		}
	}

/* ===============================================
  Smooth scroll
=============================================== */
	function SmoothnessScroll(){
		$('a[href^="#"]').click(function(){
			$(this).scrollTo(500);
			return false;
		});
	}
	
	jQuery.fn.extend({
		scrollTo : function(speed, easing){
			if(!$(this)[0].hash || $(this)[0].hash == "#"){
				return false;
			}
			return this.each(function() {
				var targetOffset = $($(this)[0].hash).offset().top;
				$('html,body').animate({scrollTop: targetOffset}, speed, easing);
			});
		}
	});

/* ===============================================
  input,textarea Focus
=============================================== */
	function InputFocus(){
		$('input[type=text],input[type=password],textarea').addClass('input-usually');
		$('.input-usually').focus(function(){
			$(this).addClass('input-focus');
		});
		$('.input-usually').blur(function(){
			if($(this).find('.input-focus')){
				$(this).removeClass('input-focus');
			}
		});
	}


/* ===============================================
  Drop down menu
=============================================== */

	$(function(){
			$('li.headlink ul').css('display', 'none');
		});

	function DropDown(){
		$(document).ready(function(){
				$('li.headlink').hover(
					function() { $('ul', this).css('display', 'block'); },
					function() { $('ul', this).css('display', 'none'); });
			});

	}

/* ===============================================
  Run functions
=============================================== */
$(document).ready(function(){
	//Roll over
	initRollOverImages();
	//Smooth scroll
	SmoothnessScroll();
	//input textarea focus
	InputFocus();
	//Drop down menu
	DropDown();
});
