/**
 * @requires jQuery 1.6.2+
 * @requires DD_belatedPNG
 *
 */
jQuery.noConflict();

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(e,b,a){if(arguments.length>1&&(b===null||typeof b!=="object")){a=jQuery.extend({},a);if(b===null)a.expires=-1;if(typeof a.expires==="number"){var d=a.expires,c=a.expires=new Date;c.setDate(c.getDate()+d)}return document.cookie=[encodeURIComponent(e),"=",a.raw?String(b):encodeURIComponent(String(b)),a.expires?"; expires="+a.expires.toUTCString():"",a.path?"; path="+a.path:"",a.domain?"; domain="+a.domain:"",a.secure?"; secure":""].join("")}a=b||{};c=a.raw?function(f){return f}:
decodeURIComponent;return(d=RegExp("(?:^|; )"+encodeURIComponent(e)+"=([^;]*)").exec(document.cookie))?c(d[1]):null};

// pngfix ( for IE 6 )
if( typeof DD_belatedPNG != 'undefined' ) {
	DD_belatedPNG.fix('#content_header img');
}

jQuery(function($) {
	/**
	 *
	 * fontsize
	 *
	 */
	var fontsize = $.cookie('fontsize') || 'fontsize-m';
	$('body').addClass(fontsize);
	$('#fontsize li').each(function() {
		var $this = $(this);
		var size = $this.attr('class');
		var date = new Date();

		// + 1 year
		date.setFullYear(date.getFullYear() + 1);

		$this.find('a').click(function(e) {
			$('body').removeClass('fontsize-s fontsize-m fontsize-l').addClass(size);
			$.cookie('fontsize', size, { expires: date })
			return false;
		});
	});

	/**
	 * lightbox
	 *
	 */
	if( typeof $.fn.lightBox == 'function' ) {
		$('a[href$=jpeg], a[href$=jpg], a[href$=png], a[href$=gif]').each(function(){
			$(this).lightBox();
		});
	}

	/**
	 * .hover-hl (highlight)
	 *
	 */
	$('.hover-hl').each(function(){
		$(this).hover(
			function(){
				$(this).animate({opacity: 0.85}, 100);
			},
			function(){
				$(this).animate({opacity: 1}, 100);
			}
		);
	});

	/**
	 * .hover-ro (rollover)
	 *
	 */
	$('.hover-ro img, img.hover-ro, input[type=image].hover-ro').each(function(){
		var thisSrc = this.src;
		var overSrc = this.src.replace(/\.(gif|png|bmp|jpe?g)$/, '_on.$1');
		var overObj = new Image();
		overObj.src = overSrc;
		$(this).hover(
			function(){ this.src = overSrc; },
			function(){ this.src = thisSrc; }
		);
	});

	/**
	 * .pagetop
	 *
	 */
	$('#pagetop a, .pagetop a').each(function(){
		$(this).click(function(){
			$('html, body').animate({ scrollTop: 0 }, '3000', 'easeOutExpo');
			return false;
		});
	});

	/**
	 * anchor link
	 *
	 */
	$('a[href^=#]').each(function(){
		var $a = $(this);
		$a.click(function(){
			var target = $($a.attr('href')).offset();
			if( target ) {
				var wh = $(window).height();
				var dh = $(document).height();
				var st = ( dh - target.top > wh ) ? Math.floor(target.top) : Math.floor(dh - wh);
				$('html, body').animate({ scrollTop: st }, '3000', 'easeOutExpo');
			}
			return false;
		});
	});

	/**
	 * .faqArea
	 *
	 */
	$('.faqArea').each(function(){
		var $a = $('.faq_answer', this);
		$a.hide();

		$('.faq_question', this).click(function(){
			$a.slideToggle(250, 'swing');
			return false;
		});
	});

	/**
	 * .tabArea
	 *
	 */
	$('.tabArea').each(function(i){
		var $tabLinks = $('.tabs a', this);
		var $contents = $('.tab_content', this);

		function initArea() {
			$tabLinks.stop(true, true).removeClass('current');
			$contents.stop(true, true).hide();
		};

		// show first
		initArea();
		$contents.eq(0).show();
		$tabLinks.eq(0).addClass('current');

		$tabLinks.each(function(i){
			var $tabLink = $(this);
			var targetID = $(this).attr('href');
			$(this).unbind('click');
			$(this).click(function(){
				initArea();
				$(targetID).fadeIn(800);
				$tabLink.addClass('current');
				return false;
			});
		});
	});
});

