var i = 1;
$(window).load(function() {
	$('#slider').nivoSlider({
		//effect:'fold', //Specify sets like: 'fold,fade,sliceDown'
		//slices:15,
		animSpeed:1000, //Slide transition speed
		pauseTime:10000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
    controlNavThumbsFromRel:false, //Use image rel for thumbs
		//controlNavThumbsSearch: '.jpg', //Replace this with...
		//controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){
		  if(i>=7){i=1;}else{i=i+1;}
		  $('#footer').removeClass('bg1');
		  $('#footer').removeClass('bg2');
		  $('#footer').removeClass('bg3');
		  $('#footer').removeClass('bg4');
		  $('#footer').removeClass('bg5');
		  $('#footer').removeClass('bg6');
		  $('#footer').removeClass('bg7');
      $('#footer').addClass('bg'+i);
		  $('#header').removeClass('bg1');
		  $('#header').removeClass('bg2');
		  $('#header').removeClass('bg3');
		  $('#header').removeClass('bg4');
		  $('#header').removeClass('bg5');
		  $('#header').removeClass('bg6');
		  $('#header').removeClass('bg7');
      $('#header').addClass('bg'+i);
		  $('#sections').removeClass('bg1');
		  $('#sections').removeClass('bg2');
		  $('#sections').removeClass('bg3');
		  $('#sections').removeClass('bg4');
		  $('#sections').removeClass('bg5');
		  $('#sections').removeClass('bg6');
		  $('#sections').removeClass('bg7');
      $('#sections').addClass('bg'+i);
		  $('#icq').removeClass('bg1');
		  $('#icq').removeClass('bg2');
		  $('#icq').removeClass('bg3');
		  $('#icq').removeClass('bg4');
		  $('#icq').removeClass('bg5');
		  $('#icq').removeClass('bg6');
		  $('#icq').removeClass('bg7');
      $('#icq').addClass('bg'+i);
    },
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});

$(document).ready(function(){

  // AutoForm Value
  $('.search').click(function(){
    var value = $(this).val();
    if(value == 'Поиск...'){$(this).val('');}
  });
  $('.search').blur(function(){
    var value = $(this).val();
    if(value == ''){$(this).val('Поиск...');}
  });
  // END AutoForm Value
  
  // Menu
  $('#topmenu ul li').hover(function(){
    $(this).children('.menul').children('.menur').children('.menub').children('.submenu').show();
  },function(){
    $(this).children('.menul').children('.menur').children('.menub').children('.submenu').hide();
  });
  $('.menul .submenu ul li').hover(function(){
    $(this).children('.submenu').show();
  },function(){
    $(this).children('.submenu').hide();
  });
  /*$('#topmenu ul li').hover(function(){
    $(this).find('.submenu').show(); //.children('.submenu')
  },function(){
    $(this).find('.submenu').hide();
  });*/
  // END Menu
  
  // Sizer
  var elem = $(window);
  var hh = elem.height();
  var res_hh = hh - 200;
  $('#content .zone').css({'height' : res_hh});
  // END Sizer
  
  // Sliz
  $('#topmenu a').click(function(){
    return false;
  });
  $('.banner a').click(function(){
    return false;
  });
  $('#topmenu .submenu .submenu a').click(function(){
    if($('.section').height()==0)
    {
      $('#mbg').addClass('pod');
      $('#mbg').animate({opacity: 0.7},400);
      $('.lists').animate({width: "720px"},800,function(){$('#sections .lists .close').show();});
      $('.section').animate({height: "65px", padding: "35px 0px 0px 0px"},400,function(){$('.top_section').animate({height: "40px", padding: "20px 0px 0px 0px"},400);});
    }
    $('.section').text($(this).html());
    $('.top_section').text($(this).parent().parent().parent().parent().children('a').text());
    var href = $(this).attr('href');
    var temp_html = '';
	var temp_ii = 0;
    $('#lmt li').each(function(){
      var rel = $(this).attr('rel');
      if(rel == href){
		if(temp_ii == 0){
			temp_html = temp_html+'<li rel="'+rel+'" class="first">'+$(this).html()+'</li>';
		}else{
			temp_html = temp_html+'<li rel="'+rel+'">'+$(this).html()+'</li>';
		}
		temp_ii=temp_ii+1;
      }
    });
    $('#carousel_ul').html(temp_html);
    $('.photos a').click(function(){
      var img = $(this).attr('href');
      var alt = $(this).attr('alt');
      var ids = $(this).attr('class');
	  var wid = $(this).attr('rel');
      $('.zone').html('<div class="photo"></div>');
      $('.photo').html('<img src="'+ img +'" alt="'+ alt +'" title="'+ alt +'" style="display: none;"/>');
      $('.photo img').fadeIn('800');
      var res_hh2 = res_hh-10;
      if(wid<400){$('#temp').css({'height' : res_hh});}else{$('#temp').css({'width' : '400px', 'margin' : '125px -20px 0 -80px'});}
      $('.prop').hide();
      $('.'+ids).fadeIn('800');
      return false;
    });
    return false;
  });
  // Sliz
  $('#close').click(function(){
    $('.top_section').text();
    $('.section').text();
    $('.lists').animate({width: "0px"},800,function(){$('#sections .lists .close').hide();});
    $('.top_section').animate({height: "0px", padding: '0px 0px 0px 0px'},400,function(){$('.section').animate({height: "0px", padding: '0px 0px 0px 0px'},400);});
    $('#mbg').animate({opacity: 0},400,function(){$('#mbg').removeClass('pod');});
    $('.zone').html('');
    $('.prop').hide();
    return false;
  });
  // END Sliz
  
  $('.phone').click(function(){
    $('.photos a').click(function(){
    });
  });
  
  // Photos
  /*
  $('.photos a').click(function(){
    var img = $(this).attr('href');
    var alt = $(this).attr('alt');
    var ids = $(this).attr('class'); 
    $('.zone').html('<div class="photo"></div>');
    $('.photo').html('<img src="'+ img +'" alt="'+ alt +'" title="'+ alt +'" style="display: none;"/>');
    $('.photo img').fadeIn('800');
    var res_hh2 = res_hh-10;
    if($('#content .zone .photo img').width()<400){$('#content .zone .photo img').css({'height' : res_hh});}else{$('#content .zone .photo img').css({'width' : '400px', 'margin' : '125px -20px 0 -80px'});}
    $('.prop').hide();
    $('.'+ids).fadeIn('800');
    return false;
  });
  */
  // END Photos

  // Roll menu
  $('#carousel_ul li:first').before($('#carousel_ul li:last'));
  $('#right_scroll a').click(function(){
	  var inte = 0;
	  $('#carousel_ul li').each(function(){ inte++;});
      //if($('#carousel_ul li:gt(6)').attr('class')!='first' && $('#carousel_ul li:gt(5)').attr('class')!='first' && $('#carousel_ul li:gt(4)').attr('class')!='first' && $('#carousel_ul li:gt(3)').attr('class')!='first' && $('#carousel_ul li:gt(2)').attr('class')!='first' && $('#carousel_ul li:gt(1)').attr('class')!='first' && $('#carousel_ul li:gt(0)').attr('class')!='first')
	  if(inte>5)
	  {
		  var item_width = $('#carousel_ul li').outerWidth() + 0;
		  var left_indent = parseInt($('#carousel_ul').css('left')) - item_width;
		  $('#carousel_ul:not(:animated)').animate({'left' : left_indent},500,function(){
			  $('#carousel_ul li:last').after($('#carousel_ul li:first'));
			  $('#carousel_ul').css({'left' : '0px'});
		  });
	  }
	  return false;
  });
  $('#left_scroll a').click(function(){
	  var inte = 0;
	  $('#carousel_ul li').each(function(){ inte++;});
      //if($('#carousel_ul li:gt(0)').attr('class')!='first' && $('#carousel_ul li:gt(1)').attr('class')!='first')
	  if(inte>5)
	  {
		  var item_width = $('#carousel_ul li').outerWidth() + 0;
		  var left_indent = parseInt($('#carousel_ul').css('left')) + item_width;             
		  $('#carousel_ul:not(:animated)').animate({'left' : left_indent},500,function(){              
		 $('#carousel_ul li:first').before($('#carousel_ul li:last')); 
		  $('#carousel_ul').css({'left' : '0px'});
		});
	  }
    return false;
  });
  // END Roll Menu
  
  $('.banner').cycle({
	fx:     'fade',
	speed: 2500,
	timeout: 6000
  });
  
  $('.roller').click(function(){
	var icq = 'icq';
	var pos_left = $('#'+icq).css('left');
	if(pos_left!='0px'){$('#'+icq).animate({left: '0px'}, 800);}
	else{$('#'+icq).animate({left: '-170px'}, 800);}
  });
  //akcii
  $('.banner a').click(function(){
    if($('.section').height()==0)
    {
      $('#mbg').addClass('pod');
      $('#mbg').animate({opacity: 0.7},400);
      $('.lists').animate({width: "720px"},800,function(){$('#sections .lists .close').show();});
      $('.section').animate({height: "65px", padding: "35px 0px 0px 0px"},400,function(){$('.top_section').animate({height: "40px", padding: "20px 0px 0px 0px"},400);});
    }
    //$('.section').text($(this).html());
	$('.section').text('New Collection');
    $('.top_section').text($(this).parent().parent().parent().parent().children('a').text());
    var href = $(this).attr('href');
    var temp_html = '';
	var temp_ii = 0;
    $('#lmt li').each(function(){
      var rel = $(this).attr('rel');
      if(rel == href){
		if(temp_ii == 0){
			temp_html = temp_html+'<li rel="'+rel+'" class="first">'+$(this).html()+'</li>';
		}else{
			temp_html = temp_html+'<li rel="'+rel+'">'+$(this).html()+'</li>';
		}
		temp_ii=temp_ii+1;
      }
    });
    $('#carousel_ul').html(temp_html);
    $('.photos a').click(function(){
      var img = $(this).attr('href');
      var alt = $(this).attr('alt');
      var ids = $(this).attr('class');
	  var wid = $(this).attr('rel');
      $('.zone').html('<div class="photo"></div>');
      $('.photo').html('<img src="'+ img +'" alt="'+ alt +'" title="'+ alt +'" style="display: none;"/>');
      $('.photo img').fadeIn('800');
      var res_hh2 = res_hh-10;
      if(wid<400){$('#temp').css({'height' : res_hh});}else{$('#temp').css({'width' : '400px', 'margin' : '125px -20px 0 -80px'});}
      $('.prop').hide();
      $('.'+ids).fadeIn('800');
      return false;
    });
    return false;
  });

});
