$(document).ready(function()
{		
  removeLinks();
	initNavigation();
	$('#nav li ul.sub-menu').wrap('<div class="drop" />');
	$('#main .box style').remove();
	$('#main .box br').remove();
	$('#main .visual ul.press li img').mouseenter(function(){
	  $(this).animate({
	    opacity: 1
	  });
	});
	$('#main .visual ul.press li img').mouseleave(function(){
	  $(this).animate({
	    opacity: 0.7
	  });
	});
	gallery_size();
	press_size();
	/*$("#next-arrow a").oneTime(20000, function() {
	    $(this).addClass('hideIt');
	});*/
	$("#next-arrow a").oneTime(1000, function() {
	      $(this).animate({ opacity: 0.5 }, 1000, function(){
	        $(this).oneTime(3000, function(){
	          $(this).animate({ opacity: 0 }, 1000);
	        });
	      });
	  });
	$("#next-arrow a").mouseenter(function() {
	      $(this).stopTime();
	      $(this).animate({ opacity: 1 }, 1000);
	});
	$("#next-arrow a").mouseleave(function() {
	      $(this).animate({ opacity: 0.5 }, 1000);
	      $(this).oneTime(3000, function(){ $(this).animate({opacity: 0}, 1000); });
	});
	$('#next-arrow a').click(function(){ nextArrow(); return false;	});
	$('#description .prebtn a').click(function(){ $('#next-arrow span').text('1') });
});

function nextArrow(){
  var $index = parseInt($('#next-arrow span').text());
  $.scrollTo('.gallery .gallery-item:eq('+ $index +')', 1000, {easing:'linear'}, {axis:'x'});
  var $gallery_items = $('#returnTo .gallery .gallery-item').size();
  $index+=1; 
  if($index==$gallery_items){ 
    $('#next-arrow span').text('0'); 
  }else{ 
    $('#next-arrow span').text($index); 
  }
}
function initNavigation()
{
	$('.navigation ol li a').hover(function()
	{
		$(this).parent().addClass('hover');
	},
	function()
	{
		$(this).parent().removeClass('hover');
		setTimeout(function(){Cufon.refresh('.navigation > ol > li > a')}, 11);
	});
}

function removeLinks(){
  var $gallery_items = $('#returnTo .gallery .gallery-item').size();
  var $img ="";
  for (i=0;i<$gallery_items;i++){
    $img = $('.gallery-item:eq('+ i +') .gallery-icon img');
    $('.gallery-item:eq('+ i +') .gallery-icon a').remove();
    $('.gallery-item:eq('+ i +') .gallery-icon').append($img);
  }
}

function gallery_size() {
  var $gallery_items = $('#returnTo .gallery .gallery-item').size();
  var $gallery_size = 0;
  for (i=0;i<$gallery_items;i++){
    $gallery_size += $('.gallery-item:eq('+ i +') .gallery-icon img').attr('width');
  }
  var $margins=$gallery_items*10;
  $('.visual').css('width', $gallery_size+$margins+285);
  $('.gallery').css('width', $gallery_size+$margins);
  $('.box').localScroll({
	   axis:'x',
	 	 offset: -30,
		 duration: 1000
	});
}

function press_size() {
  var $gallery_items = $('#main .visual ul.press li').last().index();
  var $gallery_size = 0;
  for (i=0;i<=$gallery_items;i++){
    $gallery_size += $('#main .visual ul.press li:eq('+ i +') img').attr('width');
  }
  $('#main .visual ul.press').css('width', $gallery_size+200);
}
