var lightBoxTxtImage = 'Image';
var lightBoxTxtOf = 'of';
var lightBoxExtAttrText = 'Скачать HQ фото';
var youtubeMainVideos = new Object();
$(document).ready(function(){
	$("#menu ul li").hover(
		function()
		{
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(300);
		},
		function()
		{
			$(this).find('ul:first').css({visibility: "hidden"});
		}
	);
	$('#content a.lightbox, #content a.lightbox_poster').lightBox({
        txtImage: lightBoxTxtImage,
        txtOf: lightBoxTxtOf,
        fixedNavigation: true,
        extAttrText: lightBoxExtAttrText,
        imageLoading: '/images/lightbox/lightbox-ico-loading.gif',
        imageBtnClose: '/images/lightbox/lightbox-btn-close.gif',
        imageBtnPrev: '/images/lightbox/lightbox-btn-prev.png',
        imageBtnNext: '/images/lightbox/lightbox-btn-next.png',
        imageBlank: '/images/lightbox/lightbox-blank.gif',
        otherInfo:  'При использовании фото ссылка на Star Media обязательна'
	});
	$('#main_videos li.video_thumb').click(function(){
		if ($(this).hasClass('selected'))
			return false;
		var html = youtubeMainVideos[$(this).attr('rel')];
		//var html = $(this).find('div.hidden').html();
		$('#main_video').html(html);
		$('#main_video .video_cont div.play_button_foreground').click(function(){
			$(this).hide();
      $(this).prev().hide();
			/*$(this).siblings('img').hide();*/
			$(this).siblings('.video').show();
		});
		$(this).siblings('li').removeClass('selected');
		$(this).addClass('selected');
    
    $.cookie('active_project', $(this).attr('rel'), {'path' : '/'});
	});
  
    if (window.location.href.indexOf("#") > -1 || $('#main_videos .thumb_container').length > 0)
    {
		var active_project = window.location.hash.replace('#', '');
		  
		if (active_project == '')
		  active_project = $.cookie('active_project');
		else
		{
		  window.location.hash = '';
		  if (!!(window.history && history.pushState))
			history.replaceState("", document.title, window.location.href.replace('#', ''));	

      	  $.cookie('active_project', active_project, {'path' : '/'});
		}
		 
		if ($('#main_videos .thumb_container').length > 0)
		{
			if (typeof active_project != 'undefined' && active_project != '')
			  $('#main_videos li[rel='+ active_project +']').click();
				
			var list_num = $('#main_videos li').index($('#main_videos li[rel='+ active_project +']'));
		  
			$('#main_videos .thumb_container').easySlider({
				prevId: 'prevVideos',
				nextId: 'nextVideos',
				firstEl: list_num
			});
	    }
	}
	
	$('.cornered').prepend('<ins class="tl"></ins><ins class="tr"></ins><ins class="br"></ins><ins class="bl"></ins>');
	$('.bordered').prepend('<ins class="t"></ins><ins class="r"></ins><ins class="b"></ins><ins class="l"></ins>');
	
	$('.filters form').jqTransform({
        imgPath: '../images/jqtransform/',
        transformInputs: false
    });
	
	$('.video_cont div.play_button_foreground').click(function(){
		if ($(this).siblings('.video').find('iframe, #videoplayer').length > 0)
		{
			$(this).hide();
			/*$(this).siblings('img').hide();*/
      $(this).prev().hide();
			$(this).siblings('.video').show();
      if ($('#videoplayer video').length > 0)
          $('#videoplayer video')[0].play();
		}
	});
  
	$('#project_photos .thumb_container').easySlider({
		prevId: 'prevPhotos',
		nextId: 'nextPhotos'
	});
  
	if ('ontouchstart' in document) {
		$('body').removeClass('no-touch');
	}
  
  
  $('.catalog li').bind('touchstart, click', function(){
    if (!$(this).hasClass('hover'))
    {
      $('.catalog').addClass('un_active');
      $('.catalog li').removeClass('hover')
      $(this).addClass('hover');
      /*$('body').addClass('close_list');
      $('body.close_list:not(div.format)').bind('touchstart, mousedown', function(){
        $('.catalog').removeClass('un_active');
        $('.catalog li').removeClass('hover');
      }); */
    }
    else
    {
      $('.catalog').removeClass('un_active');
      $(this).removeClass('hover').find('.format').css('visibility', 'hidden');
      setTimeout(function(){$('.catalog .format').removeAttr('style');}, 500);
    }
  });
});

function stopWheel(e){
    if(!e){ /* IE7, IE8, Chrome, Safari */ 
        e = window.event; 
    }
    if(e.preventDefault) { /* Chrome, Safari, Firefox */ 
        e.preventDefault(); 
    } 
    e.returnValue = false; /* IE7, IE8 */
}

$(window).load(function(){
	$('.scrollable').jScrollPane({showArrows: true});
  
  $('.format').hover(
    function() {
      $(document).bind('mousewheel DOMMouseScroll',function(e){
          stopWheel(e); 
      });
    }, 
    function() {
        $(document).unbind('mousewheel DOMMouseScroll');
    }
  );
    /*
  $('.jspPane div').mousedown(function () {
    el = this;
    sel = setTimeout(function(){
      var w = window.getSelection();
      w.removeAllRanges();  // вроде бы старые промежутки удаляются автоматически при каждом клике
      var range = document.createRange();
      range.selectNode(el);
      w.addRange(range);
      $(el).mousedown(function(){return false;})
    }, 1000);
  });   
  $('.jspPane div').mouseup(function(){
    clearTimeout(sel);
  }); */
});
