$(function(){
 
  
  if ($.browser.msie && $.browser.version == '6.0') {
    window.attachEvent('onload', mmwidth);
    window.attachEvent('onresize', mmwidth);
    function mmwidth(){
      document.getElementById('main-wrp').style.width = ((document.documentElement.clientWidth || document.body.clientWidth) < 995) ? '995px' : ((document.body.clientWidth > 1280) ? '1280px' : '100%');
    };
  };
	
	
	
	$('span.za-rul > a').live('click',function(e){
		var current = $('span.za-rul > a.show');
		var next = current.next().length ? current.next() : current.parent().children(':first');
		current.removeClass('show');

		if (typeof current.css('background-position') != undefined) {
			var bkd_position = current.css('background-position').split(' ');
			var position = parseInt(bkd_position[1]);
		}
		
		position =  position - 185;
		next.addClass('show').css('background-position', '0px ' + position + 'px');
		
		var numberOfPhoto = $('span.za-rul > a').length;
		var links = $('span.za-rul a');
		
		for (var i = 0; i < numberOfPhoto; i++) {
      if (i == 0) {
        links.first().css('background-position', '0px 0px');
      }
      else if (i+1 == numberOfPhoto) {
        links.last().css('background-position', '0px -925px');
			}
      else if (i-1 > 0 && (i-1) % 4 == 0 && links.eq(i).hasClass('show')) {
        next.css('background-position', '0px -185px');
        break;
      }
    }
    
		return false;
});


  
  $('ul.list-photo a').click(function(){
    var ul = $(this).closest('ul.prod-list');
    var num = $(this).parent().prevAll().size();
    ul.find('a').removeClass('active-prod');
    $(this).addClass('active-prod');
    
    $('#prod-img').html('<img src=' + $(this).parent().attr('rel') + ' alt="" />');
    $('#prod-img').attr('href', $(this).attr('href'));
    return false;
  });
  $('ul.list-photo a:first').click();
  $('div.personal-type a').live('click',function(){
    var strongText = $(this).siblings('strong').text();
    
    
    if ($.browser.msie && $.browser.version == '6.0') {
        
        $(this).closest('div.personal').toggleClass('management'); 
        $(this).siblings('strong').replaceWith('<a href="#" class="dotted">' + strongText + '</a>');
        $(this).replaceWith('<strong>' + $(this).text()+'</strong>');
        $('div.wrapper').css('height','auto');
        $('div.wrapper').css('height','100%');
               
      } else {
        
        $(this).closest('div.personal').toggleClass('management'); 
        $(this).siblings('strong').replaceWith('<a href="#" class="dotted">' + strongText + '</a>');
        $(this).replaceWith('<strong>' + $(this).text()+'</strong>');
        
      }
    return false;
  });
  
  
  $('#map .map-sw').click(function(){
      $('#map .map-sw').removeClass('selected-map');
      $(this).addClass('selected-map');
      $('#map').addClass('map-open');
      if ($.browser.msie && $.browser.version == '6.0') {
        $("#map").height(511);
        $('div.wrapper').css('height','auto');
        $('div.wrapper').css('height','100%');        
      } else {
        $('#map').addClass('map-self');
        $("#map").animate({height: "511px"}, 500);  
      }
    return false;
  });
  
  $('#map-sw-self').click(function(){
    $('#map').addClass('map-self');
    $('#map #map-image').attr('src', '/images/map3.jpg');
  });
  $('#map-sw-car').click(function(){
    $('#map').removeClass('map-self');
    $('#map #map-image').attr('src', '/images/map1.jpg');
  });
  $('#map #map-image').attr('src', '/images/map1.jpg');
  //$('#map-sw-car').click();

  $('#map .to-print').click(function(){
    window.print();
  })

  

  
$('div.faq-item > h2 > a').click(
function() {
  if ($.browser.msie && $.browser.version == '6.0') {
        $(this).closest('div.faq-item').siblings('div.faq-item').children('p').hide();
        $(this).parent().siblings('p').toggle();
        $('div.wrapper').css('zoom','1');        
      } else {
        $(this).closest('div.faq-item').siblings('div.faq-item').children('p').hide();
        $(this).parent().siblings('p').toggle();
      }
  return false;       
});

$('input, textarea','.hi').focus(function(){
  $(this).siblings('label').hide();
}).blur(function(){
  if ($(this).val() == '') {
    $(this).siblings('label').show();  
  }
});

$('label','form.hi').click(function(){
  $(this).hide().siblings('input, textarea').eq(0).focus();
  return false;
});



$('input, textarea','#request-form').each(function(){
  if ($(this).val() != '') {
    $(this).siblings('label').hide();  
  }
});

$('#content .gallery-thmb a').lightBox({
    containerResizeSpeed: 500
  });
  
  $('div.gallery-thmb a').hover(function(){
    $(this).addClass('hovered-img');
  }, function(){
    $(this).removeClass('hovered-img');
  });



  
});






