﻿/*
* cross-fading rotating images (slideshow)
* author ( email )
* url
* rotator.js
*/
// Initialize.
function init_rotator() {

	// Does element exist?
	if (!$('#rotator').length) {

		// If not, exit.
		return;
	}
	
	// Rotate speed.
	// Slide on screen time
	var speed = 10000;
	// Slide fade out time
	var speedout = 1500;
	// Slide fade in time
	var speedin = 1500;

	// Pause setting.
	var pause = false;

	// Rotator function.
	function rotate(element) {

		// Stop, if user has interacted.
		if (pause) {
			return;
		}

		// Either the next /first <li>.
		var $next_li = $(element).next('li').length ? $(element).next('li') : $('#rotator li:first');

		// Either next / first control link.
		var $next_a = $('#rotator_controls a.current').parent('li').next('li').length ? $('#rotator_controls a.current').parent('li').next('li').find('a') : $('#rotator_controls a:first');

		// Animate.
		$('#rotator_controls a.current').removeClass('current');
		$next_a.addClass('current');

		// Continue.
		function doIt() {
			rotate($next_li);
		}

		// Fade out <li>.
		$(element).fadeOut(speedout);

		// Show next <li>.
		$($next_li).fadeIn(speedin, function() {

			// Slight delay.
			setTimeout(doIt, speed);
		});
	}

	// Add click listeners for controls.
	$('#rotator_controls a').click(function() {

		// Change button text.
		$('#rotator_play_pause').html('Play');

		// Show target, hide other <li>.
		$($(this).attr('href')).show().siblings('li').hide();

		// Add class="current" and remove from all others.
		$(this).addClass('current').parent('li').siblings('li').find('a').removeClass('current');;

		// Pause animation.
		pause = true;

		// Nofollow.
		this.blur();
		return false;
	});

	// Pause / Play the animation.
	$('#rotator_play_pause').click(function() {

		// What does the button say?
		if ($(this).html() === 'Pause') {

			// Stop rotation.
			pause = true;

			// Change the text.
			$(this).html('Play');

		} else {

			// Remove class="pause".
			pause = false;

			// Start the rotation.
			rotate('#rotator li:visible:first');

			// Change the text.
			$(this).html('Pause');
		}

		this.blur();
		return false;
	});

	// Hide all but first <li>.
	$('#rotator li:first').show();

	// Wait for page load.
	$(window).load(function() {

		// Begin rotation.
		rotate($('#rotator li:visible:first'));
	});
}

// Kick things off with a slight pause for the first slide.
$(document).ready(function() {
//setTimeout("init_rotator();",500);
	init_rotator()
});

/*
* vertical news ticker
* Tadas Juozapaitis ( kasp3rito@gmail.com )
* http://plugins.jquery.com/project/vTicker
* jquery.vticker-min.js
*/
(function(a){a.fn.vTicker=function(b){var c={speed:2000,pause:10000,showItems:1,animation:"fade",mousePause:true,isPaused:false,direction:"up",height:0};var b=a.extend(c,b);moveUp=function(g,d,e){if(e.isPaused){return}var f=g.children("ul");var h=f.children("li:first").clone(true);if(e.height>0){d=f.children("li:first").height()}f.animate({top:"-="+d+"px"},e.speed,function(){a(this).children("li:first").remove();a(this).css("top","0px")});if(e.animation=="fade"){f.children("li:first").fadeOut(e.speed);if(e.height==0){f.children("li:eq("+e.showItems+")").hide().fadeIn(e.speed)}}h.appendTo(f)};moveDown=function(g,d,e){if(e.isPaused){return}var f=g.children("ul");var h=f.children("li:last").clone(true);if(e.height>0){d=f.children("li:first").height()}f.css("top","-"+d+"px").prepend(h);f.animate({top:0},e.speed,function(){a(this).children("li:last").remove()});if(e.animation=="fade"){if(e.height==0){f.children("li:eq("+e.showItems+")").fadeOut(e.speed)}f.children("li:first").hide().fadeIn(e.speed)}};return this.each(function(){var f=a(this);var e=0;f.css({overflow:"hidden",position:"relative"}).children("ul").css({position:"absolute",margin:0,padding:0}).children("li").css({margin:0,padding:0});if(b.height==0){f.children("ul").children("li").each(function(){if(a(this).height()>e){e=a(this).height()}});f.children("ul").children("li").each(function(){a(this).height(e)});f.height(e*b.showItems)}else{f.height(b.height)}var d=setInterval(function(){if(b.direction=="up"){moveUp(f,e,b)}else{moveDown(f,e,b)}},b.pause);if(b.mousePause){f.bind("mouseenter",function(){b.isPaused=true}).bind("mouseleave",function(){b.isPaused=false})}})}})(jQuery);

/*
* xhtml strict friendly iframe
* Andrew P Watson ( contact@andrewpwatson.com )
* http://www.andrewpwatson.com/posts/create-valid-xhtml-strict-search-friendly-iframes-using-jquery
* exssfiuj.js
*/
$(document).ready( function() {
// create xhtml strict friendly iframe
$('a.iframe').each(
function (i) {
$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' class='autoHeight'></iframe>");
}
);
});

/*
* autoheight friendly iframe
* Lost-in-code ( www.lost-in-code.com )
* http://www.lost-in-code.com/programming/jquery-auto-iframe-height/
* http://lib.mobius.tw/jquery/myplugin/iframe_autoHeight/api.htm
* jquery.autoheight.js
*/
function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}

$(document).ready(function(){
	//hide the all of the element with class msg_body
	$(".msg_body").hide();
	//toggle the componenet with class msg_body
	$(".msg_head").click(function(){
		$(this).next(".msg_body").slideToggle(600);
	});
});
// Initialize.
function init_tooltip() {

	// Does element exist?
	if (!$('.tooltip').length) {

		// If not, exit.
		return;
	}

	// Insert tooltip (hidden).
	$('body').append('<div id="tooltip"><div id="tooltip_inner"></div></div>');

	// Empty variables.
	var $tt_title, $tt_alt;

	var $tt = $('#tooltip');
	var $tt_i = $('#tooltip_inner');

	// Watch for hover.
	$('.tooltip').hover(function() {

		// Store title, empty it.
		if ($(this).attr('title')) {
			$tt_title = $(this).attr('title');
			$(this).attr('title', '');
		}

		// Store alt, empty it.
		if ($(this).attr('alt')) {
			$tt_alt = $(this).attr('alt');
			$(this).attr('alt', '');
		}

		// Insert text.
		$tt_i.html($tt_title);

		// Show tooltip.
		$tt.show();
	},
	function() {

		// Hide tooltip.
		$tt.hide();

		// Empty text.
		$tt_i.html('');

		// Fix title.
		if ($tt_title) {
			$(this).attr('title', $tt_title);
		}

		// Fix alt.
		if ($tt_alt) {
			$(this).attr('alt', $tt_alt);
		}

	// Watch for movement.
	}).mousemove(function(ev) {

		// Event coordinates.
		var $ev_x = ev.pageX;
		var $ev_y = ev.pageY;

		// Tooltip coordinates.
		var $tt_x = $tt.outerWidth();
		var $tt_y = $tt.outerHeight();

		// Body coordinates.
		var $bd_x = $('body').outerWidth();
		var $bd_y = $('body').outerHeight();

		// Move tooltip.
		$tt.css({
			'top': $ev_y + $tt_y > $bd_y ? $ev_y - $tt_y : $ev_y,
			'left': $ev_x + $tt_x + 20 > $bd_x ? $ev_x - $tt_x - 10 : $ev_x + 15
		});
	});
}

// Kick things off.
$(document).ready(function() {
	init_tooltip();
});
