
	jQuery(function($) {
		
		var $h = $(window).height();
		$('.side').css({'height':$h});
				
		$(window).resize(function() { 
			var $h = $(window).height();
			$('.side').css({'height':$h});
		});

		var $hold = Math.floor(($(window).height() - 620)/2); if($hold < 0) $hold = 0;
		$('#site,#left,#right').css({'top':$hold});
		$(window).resize(function() {
			$hold = Math.floor(($(window).height() - 620)/2); if($hold < 0) $hold = 0;
  			if($('.content').length == 0) {
				$('#site,#left,#right').css({'top':$hold});
			}
		});
		
		$('.side a em').css({'opacity':.7});
		$('.side a').hover(
			function() { $(this).find('em').stop(true,true).animate({'opacity':0},400); },
			function() { $(this).find('em').stop(true,true).animate({'opacity':.7},400); }
		);
				
		$('.more a').live({
			'mouseover': function() { $(this).parent('div').stop(true,true).animate({'opacity':1},400); },
			'mouseout': function() { $(this).parent('div').stop(true,true).animate({'opacity':.66},400); },
			'click': function() { $('.rest').slideDown(700).find('a > span').hide(0); $('.more').stop(true,true).hide(700); $('.less').stop(true,true).show(700); $('.playerwrap').stop(true,true).slideUp(function() { $(this).html(''); }); return false; }
		});
		
		$('.less a').live({
			'mouseover': function() { $(this).parent('div').stop(true,true).animate({'opacity':1},400); },
			'mouseout': function() { $(this).parent('div').stop(true,true).animate({'opacity':.66},400); },
			'click': function() { $('.rest').slideUp(700); $('.less').stop(true,true).hide(700); $('.more').stop(true,true).show(700); $('.playerwrap').stop(true,true).slideUp(function() { $(this).html(''); }); return false; }
		});
								
		$('#header > ul li a').click(function() {
			$('.bottom').stop(true,true).fadeOut(750,function() { $(this).html(''); });
			$link = $(this);
			$('#header ul li a').removeClass('active home'); 
			$link.addClass('active'); 
			$page = $('#header ul li a').index($link) + 1;
			$('#pages').stop(true,true).animate({'left':-1024*$page},750,'easeInOutQuad',function() {
				$('#site,#left,#right').animate({'top': 0},750,'easeInOutQuad');
				$('#header').animate({'top': 0},750,'easeInOutQuad');
				$('#pages').animate({'top':-456},750,'easeInOutQuad',function() {
					$('.top').removeClass('topabs').addClass('topfix');
				});
				$('.top-c').stop(true,true).fadeOut(1500);
				$.ajax({
					url: 'ajax.php',
					type: 'post',
					data: 'page=' + ($page),
					success: function($data) {
						$('#page' + ($page) + ' .bottom').html('<div class="pageholder">' + $data + '</div>');
						$('#page' + ($page) + ' .bottom').fadeIn(1500);
						$('#page' + ($page) + ' .bottom').find('a > span').hide(0);
						$('.more').css({'opacity':.66});
						stButtons.locateElements();
					}
				});
				$('.side a').animate({'top':-456},750,'easeInOutQuad').addClass('content');
				$('body').addClass('bottoms');
			});
			return false;
		});
		
		$('#header #home').click(function() {
			$('.bottom').stop(true,true).fadeOut(750,function() { $(this).html(''); });
			$link = $('#p2 a');
			$('#header ul li a').removeClass('active home'); 
			$link.addClass('active home'); 
			$('#page2 .top-c').stop(true,true).fadeIn(1500);
			$page = $('#header ul li a').index($link);
			$('.side a').animate({'top':0},750,'easeInOutQuad').removeClass('content');
			$('body').removeClass('bottoms');
			$('#site,#left,#right').animate({'top': $hold},750,'easeInOutQuad');
			$('#header').animate({'top': 220},750,'easeInOutQuad');
			$('#pages').stop(true,true).animate({'top': 0},750,'easeInOutQuad',function() {
				$('#pages').animate({'left':-2048},750,'easeInOutQuad');
			});
			return false;
		});
		
		$('.tctitle a').css({'opacity':.5});
		$('.top-a a').hover(
			function() { 
				var $color = $(this).closest('.page').attr('color');
				$(this).find('span').stop(true,true).fadeIn(400); 
				$(this).closest('.top').find('.top-c').find('.tctitle a').stop(true,true).animate({'opacity':1,'color':$color},400);
			},
			function() { 
				$(this).find('span').stop(true,true).fadeOut(400); 
				$(this).closest('.top').find('.top-c').find('.tctitle a').stop(true,true).animate({'opacity':.7,'color':'#7d7d7d'},400);
			}
		).click(function() { 
			var $image = $(this).closest('.top').find('.top-a');
			var $player = $(this).closest('.top').find('.top-b');
			var $line = $(this).closest('.top').find('.top-c');
			var $movie = $(this).attr('href');
			var $plid = $(this).attr('player');
			
			var $qua360p  = $(this).attr('qua360p');
			var $qua405p  = $(this).attr('qua405p');
			var $qua576p  = $(this).attr('qua576p');
				
			var $qua = '';
			if($qua360p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua360p + '">360P</a>';
			if($qua405p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua405p + '">405P</a>';
			if($qua576p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua576p + '">576P</a>';
			$qua = '<div class="qua">' + $qua + '</div>';
			
			$player.find('.playerwrap').html('<div class="plw" width="1024" height="576" id="' + $plid + '"></div>' + $qua + '<a class="clo" href="#"></a>');
			var $playerw = $player.find('.playerwrap');
			$playerw.show();
			//$playerw.find('.clo').show();
			//$playerw.find('.qua').show();
			
			$('#header').fadeOut(750);
			$line.fadeOut(750);
			$image.fadeOut(750,function() {
				$player.stop(true,true).fadeIn(function() {
					//$player.expose();
					jwplayer($plid).setup({ 
						file: $movie,
						modes: [ 
							{ type: "flash", src: "player/player.swf" }, 
							{ type: "html5" }, 
							{ type: "download" } 
						],
						skin: "player/hoene.zip",
						autostart: true
					});
				});
			});
			return false;
		});
		$('.tctitle a').hover(
			function() { 
				var $color = $(this).closest('.page').attr('color');
				$(this).closest('.top').find('.top-a').find('span').stop(true,true).fadeIn(400); 
				$(this).stop(true,true).animate({'opacity':1,'color':$color},400);
			},
			function() { 
				$(this).closest('.top').find('.top-a').find('span').stop(true,true).fadeOut(400); 
				$(this).stop(true,true).animate({'opacity':.7,'color':'#7d7d7d'},400);
			}
		).click(function() { 
			var $image = $(this).closest('.top').find('.top-a');
			var $player = $(this).closest('.top').find('.top-b');
			var $line = $(this).closest('.top').find('.top-c');
			var $movie = $(this).attr('href');
			var $plid = $(this).attr('player');
			
			var $qua360p  = $(this).attr('qua360p');
			var $qua405p  = $(this).attr('qua405p');
			var $qua576p  = $(this).attr('qua576p');
				
			var $qua = '';
			if($qua360p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua360p + '">360P</a>';
			if($qua405p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua405p + '">405P</a>';
			if($qua576p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua576p + '">576P</a>';
			$qua = '<div class="qua">' + $qua + '</div>';
			
			$player.find('.playerwrap').html('<div class="plw" width="1024" height="576" id="' + $plid + '"></div>' + $qua + '<a class="clo" href="#"></a>');
			var $playerw = $player.find('.playerwrap');
			$playerw.show();
			//$playerw.find('.clo').show();
			//$playerw.find('.qua').show();
			
			$('#header').fadeOut(750);
			$line.fadeOut(750);
			$image.fadeOut(750,function() {
				$player.stop(true,true).fadeIn(function() {
					//$player.expose();
					jwplayer($plid).setup({ 
						file: $movie,
						modes: [ 
							{ type: "flash", src: "player/player.swf" }, 
							{ type: "html5" }, 
							{ type: "download" } 
						],
						skin: "player/hoene.zip",
						autostart: true
					});
				});
			});
			return false;
		});
					
		$('a.video').live({
			'mouseover': function() { 
				var $color = $(this).closest('.page').attr('color');
				$(this).find('span').stop(true,true).fadeIn(400); 
				$(this).find('strong').stop(true,true).animate({'color':$color},400);
			},
			'mouseout': function() { 
				$(this).find('span').stop(true,true).fadeOut(400); 
				$(this).find('strong').stop(true,true).animate({'color':'#545454'},400);
			},
			'click': function() {
				
				var $movie = $(this).attr('href');
				var $plid = $(this).attr('player');
				var $player = $(this).prevAll('.pwh').first();
				
				var $qua360p  = $(this).attr('qua360p');
				var $qua405p  = $(this).attr('qua405p');
				var $qua576p  = $(this).attr('qua576p');
				
				var $qua = '';
				if($qua360p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua360p + '">360P</a>';
				if($qua405p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua405p + '">405P</a>';
				if($qua576p.length > 0) $qua += '<a class="quapa" player="' + $plid + '" href="' + $qua576p + '">576P</a>';
				$qua = '<div class="qua">' + $qua + '</div>';
				
				$(this).closest('.bottom').find('.playerwrap').html('<div class="plw" width="1024" height="576" id="' + $plid + '"></div>' + $qua + '<a class="clo" href="#"></a>').detach().appendTo($player);
								
				var $playerw = $player.find('.playerwrap');
				//$playerw.find('.clo').show();
				//$playerw.find('.qua').show();
				$playerw.stop(true,true).slideDown(function() {
					$playerw.expose(); 
					jwplayer($plid).setup({ 
						file: $movie,
						modes: [ 
							{ type: "flash", src: "player/player.swf" }, 
							{ type: "html5" }, 
							{ type: "download" } 
						],
						skin: "player/hoene.zip",
						autostart: true
					});
					$('html,body').animate({ 'scrollTop': $playerw.offset().top - Math.floor(($(window).height() - 528)/2) },'slow');
				});
				return false;
			}
		});
		
		$('.quapa').live('click',function() {
			var $plw = $(this).attr('player');
			var $movie = $(this).attr('href');
			jwplayer($plw).setup({ 
				file: $movie,
				modes: [ 
					{ type: "flash", src: "player/player.swf" }, 
					{ type: "html5" }, 
					{ type: "download" } 
				],
				skin: "player/hoene.zip",
				autostart: true
			});
			return false;
		});
				
		$('.bloga').live('click',function() {
			var $post = $(this).attr('post'); 
			var $tag = $(this).attr('tag'); 
			var $blogpage = $(this).attr('page'); 
			$('#page6 .bottom').fadeOut(0,function() { 
				$.ajax({
					url: 'ajax.php',
					type: 'post',
					data: 'page=6&post=' + $post + '&tag=' + $tag + '&blogpage=' + $blogpage,
					success: function($data) {
						$('#page6 .pageholder').html('<div class="pageholder">' + $data + '</div>');
						$('#page6 .bottom').fadeIn(0);
						stButtons.locateElements();
					}
				});
			});
			return false;
		});
		
		$('#left a').click(function() {
			$('.top-b').stop(true,true).hide(0,function() { 
				$('.playerwrap').html();
				$('.top-a,.top-c,#header').stop(true,true).show();
				if($('body').hasClass('bottoms')) { $('.top-c').hide(); }
			});
			var $left = $(this);
			var $link = $('#header ul li a.active').closest('li').prev('li').find('a');
			if($link.length) {
				$('#header ul li a').removeClass('active home'); 
				$link.addClass('active'); 
				$('.bottom').stop(true,true).fadeOut(750,function() { $(this).html(''); });
				$page = $('#header ul li a').index($link)+1;
				$('#left .slidingtitleholder').stop(true,true).animate({'width':0,'right':0},0);
				$('#pages').stop(true,true).animate({'left':-1024*$page},750,'easeInOutQuad',function() {
					if($left.hasClass('content')) {
						$.ajax({
							url: 'ajax.php',
							type: 'post',
							data: 'page=' + ($page),
							success: function($data) {
								$('#page' + ($page)).find('.bottom').html('<div class="pageholder">' + $data + '</div>');
								$('#page' + ($page)).find('.bottom').fadeIn(1500);
								$('#page' + ($page)).find('.bottom').find('a > span').hide(0);
								stButtons.locateElements();
							}
						});
					}
					else {
						$('#page' + ($page+1) + ' .top-c').fadeIn(1500);
					}
					$('#left .slidingtitle').hide(0).eq($page-1).show(0,function() {
						if($page > -1) {
							var $w = $(this).outerWidth();
							var $h = $(this).outerHeight(); 
							$('#left .slidingtitleholder').stop(true,true).animate({'height':$h},0).animate({'width':$w,'right':-$w},400);
						}
						else {
							$('#left .slidingtitleholder').stop(true,true).animate({'width':0,'right':0},400);
						}
					});
				});
			}
			else {
				$link = $('#header ul li a').eq(5);
				$('#header ul li a').removeClass('active home'); 
				$link.addClass('active'); 
				$('.bottom').stop(true,true).fadeOut(750,function() { $(this).html(''); });
				$page = $('#header ul li a').index($link) + 1;
				$('#left .slidingtitleholder').stop(true,true).animate({'width':0,'right':0},0);
				$('#pages').stop(true,true).animate({'left':0},750,'easeInOutQuad',function() { 
					$(this).css({'left':-6144});
					if($left.hasClass('content')) {
						$.ajax({
							url: 'ajax.php',
							type: 'post',
							data: 'page=' + ($page),
							success: function($data) {
								$('#page' + ($page)).find('.bottom').html('<div class="pageholder">' + $data + '</div>');
								$('#page' + ($page)).find('.bottom').fadeIn(1500);
								$('#page' + ($page)).find('.bottom').find('a > span').hide(0);
								stButtons.locateElements();
							}
						});
					}
					else {
						$('#page' + ($page) + ' .top-c').fadeIn(1500);
					}
					$('#left .slidingtitle').hide(0).eq($page-1).show(0,function() {
						if($page > -1) {
							var $w = $(this).outerWidth();
							var $h = $(this).outerHeight(); 
							$('#left .slidingtitleholder').stop(true,true).animate({'height':$h},0).animate({'width':$w,'right':-$w},400);
						}
						else {
							$('#left .slidingtitleholder').stop(true,true).animate({'width':0,'right':0},400);
						}
					});
				});
			}
			return false;
		}).hover(
			function() {
				var $link = $('#header ul li a.active').closest('li').prev('li').find('a');
				/*if($link.length) {*/
					var $page = $('#header ul li a').index($link)+1; 
					$('#left .slidingtitle').hide(0).eq($page).show(0,function() {
						var $w = $(this).outerWidth();
						var $h = $(this).outerHeight();
						$('#left .slidingtitleholder').stop(true,true).animate({'height':$h},0).animate({'width':$w,'right':-$w},400);
					});
				/*}*/
			},
			function() {
				$('#left .slidingtitleholder').stop(true,true).animate({'width':0,'right':0},400);
			}
		);
		
		$('#right a').click(function() {
			$('.top-b').stop(true,true).hide(0,function() { 
				$('.playerwrap').html();
				if(!$('#right > a').hasClass('content')) {
					$('.top-a,.top-c,#header').stop(true,true).show();
					if($('body').hasClass('bottoms')) { $('.top-c').hide(); }
				}
			});
			var $right = $(this);
			var $link = $('#header ul li a.active').closest('li').next('li').find('a');
			if($link.length) {
				$('#header ul li a').removeClass('active home'); 
				$link.addClass('active'); 
				$('.bottom').stop(true,true).fadeOut(750,function() { $(this).html(''); });
				$page = $('#header ul li a').index($link)+1;
				$('#right .slidingtitleholder').stop(true,true).animate({'width':0,'left':0},0);
				$('#pages').stop(true,true).animate({'left':-1024*$page},750,'easeInOutQuad',function() {
					if($right.hasClass('content')) {
						$.ajax({
							url: 'ajax.php',
							type: 'post',
							data: 'page=' + ($page),
							success: function($data) {
								$('#page' + ($page)).find('.bottom').html('<div class="pageholder">' + $data + '</div>');
								$('#page' + ($page)).find('.bottom').fadeIn(1500);
								$('#page' + ($page)).find('.bottom').find('a > span').hide(0);
								stButtons.locateElements();
							}
						});
					}
					else {
						$('#page' + ($page+1) + ' .top-c').fadeIn(1500);
					}
					$('#right .slidingtitle').hide(0).eq($page + 1).show(0,function() {
						if($page < 7) {
							var $w = $(this).outerWidth();
							var $h = $(this).outerHeight(); 
							$('#right .slidingtitleholder').stop(true,true).animate({'height':$h},0).animate({'width':$w,'left':-$w},400);
						}
						else {
							$('#right .slidingtitleholder').stop(true,true).animate({'width':0,'left':0},400);
						}
					});
				});
			}
			else {
				$link = $('#header ul li a').eq(0);
				$('#header ul li a').removeClass('active home'); 
				$link.addClass('active'); 
				$('.bottom').stop(true,true).fadeOut(750,function() { $(this).html(''); });
				$page = $('#header ul li a').index($link) + 1;
				$('#right .slidingtitleholder').stop(true,true).animate({'width':0,'left':0},0);
				$('#pages').stop(true,true).animate({'left':-7168},750,'easeInOutQuad',function() {
					$(this).css({'left':-1024});
					if($right.hasClass('content')) {
						$.ajax({
							url: 'ajax.php',
							type: 'post',
							data: 'page=' + ($page),
							success: function($data) {
								$('#page' + ($page)).find('.bottom').html('<div class="pageholder">' + $data + '</div>');
								$('#page' + ($page)).find('.bottom').fadeIn(1500);
								$('#page' + ($page)).find('.bottom').find('a > span').hide(0);
								stButtons.locateElements();
							}
						});
					}
					else {
						$('#page' + ($page) + ' .top-c').fadeIn(1500);
					}
					$('#right .slidingtitle').hide(0).eq($page + 1).show(0,function() {
						if($page < 7) {
							var $w = $(this).outerWidth();
							var $h = $(this).outerHeight(); 
							$('#right .slidingtitleholder').stop(true,true).animate({'height':$h},0).animate({'width':$w,'left':-$w},400);
						}
						else {
							$('#right .slidingtitleholder').stop(true,true).animate({'width':0,'left':0},400);
						}
					});
				});
			}
			return false;
		}).hover(
			function() {
				var $link = $('#header ul li a.active').closest('li').next('li').find('a');
				if($link.length) { 
					var $page = $('#header ul li a').index($link)+1; 
				}
				else {
					var $page = 7;
				}
				$('#right .slidingtitle').hide(0).eq($page).show(0,function() {
					var $w = $(this).outerWidth();
					var $h = $(this).outerHeight(); 
					$('#right .slidingtitleholder').stop(true,true).animate({'height':$h},0).animate({'width':$w,'left':-$w},400);
				});
			},
			function() {
				$('#right .slidingtitleholder').stop(true,true).animate({'width':0,'left':0},400);
			}
		);
		
		$('#exposeMask').live('click',function() {
			if(!$('#left a').hasClass('content')) {
				$('.top-b').stop(true,true).hide(0,function() { 
					$('.playerwrap').html('');
					$('.top-a,.top-c,#header').stop(true,true).fadeIn(750);
				});
			}
			else {
				$('.playerwrap').stop(true,true).slideUp(750,function() { $(this).html(''); });
				$('.top-c').stop(true,true).fadeOut(750);
			}	
		});
		
		$('.clo').live('click',function() {
			if(!$('#left a').hasClass('content')) {
				$('.top-b').stop(true,true).hide(0,function() { 
					$('.playerwrap').html('');
					$('.top-a,.top-c,#header').stop(true,true).fadeIn(750);
				});
			}
			else {
				$('#exposeMask').click();
			}	
			return false;
		});
		
	});
