var general = {
	
	turn :null,
	
	// OnLoad functions
	init: function(){ 
		this.bubbleEvt();
	},
	
	bubbleEvt: function() {

		if($(".topblockrotator-inner").length > 0) {
			general.turn = window.setInterval('general.rotator()', 7000);
			general.initNav();
		}

		$(".cloned a").live('click', function(){
			 general.rotateMove($(".cloned a").index(this)+1);
			return false;
		});
		

		$(".puffRow .puff").hover(
			function () {
				$(this).addClass("puff-hover");
			}, 
			function () {
				$(this).removeClass("puff-hover");
			}
		);
		
		
		$(".puffRow .smallPuff").hover(
			function () {
				$(this).find(".puff-header a:nth-child(1) img").hide();
				$(this).find(".puff-header a:nth-child(2) img").show();

			}, 
			function () {
				$(this).find(".puff-header a:nth-child(1) img").show();
				$(this).find(".puff-header a:nth-child(2) img").hide();
			}
		);
		
		
		$(".puffRow .puff, .puffRow .smallPuff").click(function(){ 
			window.location.href = $(this).parent().find("a").attr("href");
		});

		
	},

	rotator: function() {
		if( $(".topblockrotator-inner .block.on").next().length != 0 ) {
			var current = $(".topblockrotator-inner .block.on");
			$(current).next().slideDown("slow", function(){$(current).removeClass("on"); $(current).next().addClass("on"); general.moveDot();} );
		} else {
			$(".topblockrotator-inner .block:not(:first-child)").slideUp("slow", function(){general.moveDot();}).removeClass("on");
			$(".topblockrotator-inner .block:first-child").addClass("on");	
		}
	},
	
	rotateMove: function(e) {
		window.clearInterval(general.turn);
		var clickedIndex = e;
		var current = $(".topblockrotator-inner .block.on");
		$(current).css("z-index","44");
		$(".topblockrotator-inner .block:not(.on)").hide();
		$(".topblockrotator-inner .block:nth-child("+clickedIndex+")").css("z-index","55");
		$(".topblockrotator-inner .block:nth-child("+clickedIndex+")").slideDown("slow", function(){
			$(".topblockrotator-inner .block").removeClass("on");
			$(".topblockrotator-inner .block:nth-child("+clickedIndex+")").addClass("on");
			general.moveDot();
		});
	},
	
	initNav: function() {
		$('.quicklinks ul').clone().appendTo('.topblockrotator').addClass("cloned").removeClass("rotator-navigator");
		$('.cloned li').html("<a href='#'></a>");
		$('.cloned li:first-child').addClass("on");
	},
	
	moveDot: function() {
		$('.cloned li').removeClass("on")
		var changeTo = $(".topblockrotator-inner div.block").index($(".topblockrotator-inner div.block.on")) +1 ;
		$(".cloned li:nth-child("+changeTo+")").addClass("on");
	},
	
	
	set_ema: function () {
		var identifyer='#mt#';
		var buff;
		var arr;
		var atags=document.getElementsByTagName('a');
		var pos;
	
		for (i=0;i<atags.length;i++) {
			//buff = ' ';
			pos = -1;
			try {
				buff = atags[i].getAttribute('href');
				pos = buff.indexOf(identifyer);
			} catch(e) {}
	
			if (pos>=0) {
				arr = buff.substr(pos+identifyer.length).split(',');
				if (arr.length>1) {
					atags[i].setAttribute('href','mai'+'lto:'+arr[0]+'@'+arr[1]);
					if (arr.length>2) {if (arr[2]=='1') {atags[i].innerHTML = arr[0]+'@'+arr[1];}}
					if (arr.length>3) {if (arr[3]=='1') {atags[i].setAttribute('title',arr[0]+'@'+arr[1]);}}
				}
			}
		}
	}
	
	
	
}

$(document).ready(function(){			   
	general.init();
});




