var scroll_int;
var hash=location.hash;

jQuery(function($) {

	init_ScrollLinks(500);

    $("a.iframe").each(function(){

        var $this     = $(this);
        var href      = $this.attr('href');

        $this
            .attr('href', '#')
            .bind('click', function(){
                $.fancybox({'padding'       : 0,
                            'transitionIn'  : 'elastic',
                		    'transitionOut' : 'elastic',
                		    'easingIn'      : 'easeOutBack',
                		    'easingOut'     : 'easeInBack',
                    	    'titlePosition' : 'over',
                        	'titlePosition' : 'over',
                            'type'          : 'iframe',
                            'speedIn'		: 700,
		                    'speedOut'		: 500,
                            'overlayOpacity': 0,
                            'width'		    : 980,
                    		'height'		: 398,
                    		'href'			: href

                });
                return false;
             });
     });

    $("a.scroll").click(function(){
				$this = $(this);
				hash = $this.attr('href');
				scroll_Content(1200);
				return false;
			});

	$('#main .article_item:first').css(
		{
		'z-index': '0',
		cursor: 'pointer'
		});


	$('#mp3_player').flash(
        { src: './page/swf/mp3player.swf',
          width: 80,
          height: 30
        });

	var h = window.location.host.toLowerCase();
	$("a[href^='http']:not(a[href^='http://" + h + "']):not(a[href^='http://www." + h + "']),a[href$='.pdf,.mp3,.jpg,.giv,.png,.aiff,.mov']").attr("target", "_blank");

});




function init_ScrollLinks(duration){

	$('#main').css('width', (($('.article_item').length)*980)+'px');

	if (hash != '' && $('.article_item').length > 0) {

		if ($('#content ' + hash).length == 0) {

			$('#content').scrollTo('0px', 1, {
				axis: 'x',
				onAfter: function(){
					scroll_Content(1200);
				}
			});
		}
		else {
			scroll_Content(1);
		}
	}

	var menu = $('#menu li a');



	menu.each(function(i){

		$this = $(this);

		if (menu.length > 0) {
			var tar = (1-(1/menu.length*i));
            var dur = 3000+(300*i);

			$this.fadeTo(dur, tar, function (){
                if (i == 0) { $('#navi_preloader').hide(); }
                $(this).css('display','block');
            });
		}

		$this.hover(
			function () {
	       		$('#menu').append($("<p>"+$(this).text()+"</p>"));
	    	},
	      	function () {
	        	$('#menu').find("p:last").remove();
	      	}
		);
	});

	menu.add('.scroll').each(function(i){
			$(this).click(function(){
				$this = $(this);
				hash = $this.attr('href');
				scroll_Content(1200);
				return false;
			});
		});

 	$('#scroll_prev').click(function () {
 		var con = $('#content');
 		var main = $('#main');
		var o = main.offset().left-con.offset().left;
		if(o == -980) {
			$('#logo_small').fadeOut(800);
		}
		$('#content').scrollTo({top: '+=0', left:'-=980'}, 800);
 	});

 	$('#scroll_next').click(function(){
 		var con = $('#content');
 		var main = $('#main');
		var o = main.offset().left-con.offset().left;
		if(o == 0) {
			$('#logo_small').fadeIn(1600);
		}
 		$('#content').scrollTo({top: '+=0', left:'+=980'}, 800);
 	});

}


function scroll_Content(duration){

	var con = $('#content');
	var tar = con.find(hash);

    if (tar.length == 0) return false;

	if (!tar.is('.article_item')){
		tar = $(hash).parents('.article_item');
	}

	var menu = $('#menu li a');
	menu.css('cursor', 'pointer');
	menu.filter('a[href$='+tar.attr('id')+']').css('cursor', 'default');

	if (hash == '#'+$('.article_item:first').attr('id')){
		$('#logo_small').fadeOut(duration);
	} else {
		$('#logo_small').fadeIn(duration);
	}

	con.scrollTo(tar, duration, {
		axis:'x',
		easing:'easeout'
	});
}

