$(document).ready(function(){

	$('#top .leftTopMenu li').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});

	$('#top .rightTopMenu li').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});

	$('#newsBox .item').click(function(){
		location.href = $(this).find('a').attr('href');
	});
	$('#newsLetterBox').click(function(){
		window.open($(this).find('a').attr('href'));
		return false;
	});
	
	$('.fancyThis').fancybox();
	
	$('#newsBox .item').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	
	$('#newsLetterBox').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	
	$('.exampleTemplate .item:last').addClass('last');
	
	$('.slideMenu .slideLink').click(function(e){
		if($(this).next().is(':visible'))
			return false;
		$('.slideMenu .moreInfo:visible').slideUp('normal');
		$(this).next().slideDown('normal');
		if($('.pageName').text() != parentTitle)
		{
			$('.pageName').fadeOut(200, function(){
				$('.pageName').text(parentTitle);
			});
			$('.pageName').fadeIn();
		}
		return false;
	});
	
	$('.triangleArea .arrowLink').hover(function(){
		$('.hiddenBoxes').find('.'+$(this).attr('rel')).show();
	}, function(){
		$('.hiddenBoxes').find('.'+$(this).attr('rel')).hide();
	});
	
	$('marquee').marquee('pointer').mouseover(function () {
		$(this).trigger('stop');
	}).mouseout(function () {
	    $(this).trigger('start');
	}).mousemove(function (event) {
	    if ($(this).data('drag') == true) {
	        this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
	    }
	}).mousedown(function (event) {
	    $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	}).mouseup(function () {
	    $(this).data('drag', false);
	});
	
	$('.newsMenu').jScrollPane(
		{
			showArrows: true,
			horizontalGutter: 10
		}
	);
	
	$('.transMenu').jScrollPane(
		{
			showArrows: true,
			horizontalGutter: 10
		}
	);
	$('.clickable').bind('click', function() {
		location.href = $(this).find('a').attr('href');
	});
	
});	

$(window).load(function(){
	if($('.pageName').hasClass('fadeRight'))
	{
		$('.pageName').css('right', function(){
			return parseInt($(this).css('right')) + 60 + 'px';
		});
		$('.pageName').animate({'opacity' : 1, 'right' : '-=60'}, 600);
	}
	else
	{
		$('.pageName').css('right', function(){
			return parseInt($(this).css('right')) - 60 + 'px';
		});
		$('.pageName').animate({'opacity' : 1, 'right' : '+=60'}, 600);
	}
	
});

function textIntro(){
	if(introMenuArray.length < 1)
		return;
	
	var item = introMenuArray.shift();
	
	var div = document.createElement('div');
	$(div).html(item);
	$(div).addClass('introItem');
	$('#top').append($(div));
	$(div).css('left', function(){
		var thisWidth = $(this).width();
		return 470 - (thisWidth / 2);
	});
	var posX = 8;
	$('#startIntroMenu ul li').each(function(){
		posX += $(this).outerWidth(true);
	});
	posX += 'px';
	var posY  = "100px";
	$(div).delay(1000).animate({ 
		left	  		: posX,
		top 	  		: posY,
		"margin-left"	: "0px",
		"font-size"		: "10px"
		}, 350, function(){
			var li = document.createElement('li');
			$(li).html($(div).html());
			$('#startIntroMenu ul').append($(li));
			$(div).remove();
			textIntro();
		});		
}


function imageIntro(){
	var imgNum = 1;
	function swapImg(){
		$('#startIntroImage img:nth-child('+ (imgNum + 1) +')').delay(600).css('opacity',0).show().animate({
			opacity : 1
		}, 300, function(){
			$('#startIntroImage img:nth-child('+ imgNum +')').hide();
			imgNum++;
			if(imgNum <= 6)
				swapImg();
			else
				textIntro();
			});
	}
	swapImg();
}

function noIntro(){
		$('#startIntroImage img:last').show().css('opacity', 1);
		for(var i in introMenuArray)
		{
			var li = document.createElement('li');
			$(li).html(introMenuArray[i]);
			$('#startIntroMenu ul').append($(li));
			
		}
}

