function isNum(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

function deleteOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
    markersArray.length = 0;
  }
}

  function codeAddress(address) {
	var data=address.split(',',2);
	var checkdata=data[0]*1+data[1]*1;
    var latlng = new google.maps.LatLng(data[0], data[1]);
	//alert(data[0] + ',' + data[1]);
	//geocoder.geocode( { 'address': address}, function(results, status) {
	//if(isNum(checkdata)) latlng = new google.maps.LatLng(data[0], data[1]);
        //map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map, 
            position: latlng
        });
  }
  
function codeMove(address) {
	var data=address.split(',',2);
	var checkdata=data[0]*1+data[1]*1;
		latlng = new google.maps.LatLng(data[0], data[1]);
		//google.maps.setMap(null);
     
        map.panTo(latlng);
}

function isNumber(e) {
   if ((e.keyCode!=43) && (e.keyCode!=32) && ((e.keyCode < 48) || (e.keyCode > 57)))
        e.returnValue = false;
}
var cur=0;
$(document).ready(function(){
						   
						   
	$('.marker').click(function(){
		if($(window).scrollTop()>250){
		  $('html, body').animate({
			scrollTop:200
		  }, 500);
		}
		codeMove($(this).attr('rel'));
		codeAddress($(this).attr('rel'));
		return false
	});  
  
  if(window.location.hash)
  {
	  var hash=window.location.hash;
	  hash=hash.replace('#','');
	  //alert(hash);
	  //alert(hash.replace('#',''));
	  $(".promo").removeClass('active');
	 if(!document.getElementById('prod-'+hash)) return false;
	  $('.main-prod').find('#prod-'+hash).addClass('active');
	var header=$('.main-prod').find('#prod-'+hash).next().find('.header').html();
	var text=$('.main-prod').find('#prod-'+hash).next().find('span').text();
	var img = $('.main-prod').find('#prod-'+hash).attr('rel');
	$(".intro-text").text(text);
		$(".lady").html(header);
		$(".main-bg").find(".content").attr({
          style: "background: url("+ img +") no-repeat 80% 20px; display:none;"});
		
	  $(".main-bg").find(".content").show();
	
		
}
  $(".promo").click(function(){
							 
	if($(window).scrollTop()>150){
	  $('html, body').animate({
        scrollTop:100
      }, 500, function(){});
	}
	$(".promo").removeClass('active');
	$(this).addClass('active');
	var header=$(this).next().find('.header').html();
	var text=$(this).next().find('span').text();
	var img = $(this).attr('rel');
	$(".main-bg").find(".content").fadeOut("slow", function(){
	if(!text)$(".intro-text").hide();
	else $(".intro-text").show();
	$(".intro-text").text(text);
		$(".lady").html(header);
		$(".main-bg").find(".content").attr({
          style: "background: url("+ img +") no-repeat 80% 20px; display:none;"});
		
	  $(".main-bg").find(".content").fadeIn("slow");
	
	});
	var hash=$(this).attr('id');
	window.location.hash=hash.replace('prod-','');
	return false;
  });
  $(".back").click(function(){
	window.history.back();
	return false;
  });
						   
  $(".box").click(function(){
	window.location = $(this).find("a").attr('href');
	return false;
  });
  $('.image').click(function(){
	var count=$("#counter").text()*1-1;
	if(cur!=count){
	var next=cur*1+1;
	
	$('.news-image').fadeOut('fast', function(){
		$('#img'+cur).hide();
		$('#img'+next).show();
		$('.news-image').fadeIn('fast');
		cur=next;
		$(".prev").show();
		if((cur*1+1)==$("#counter").text())$(".next").hide();
	});
	}
	return false;
 })
  
  $('.next').click(function(){
	var next=cur*1+1;
	
	$('.news-image').fadeOut('fast', function(){
		$('#img'+cur).hide();
		$('#img'+next).show();
		$('.news-image').fadeIn('fast');
		cur=next;
		$(".prev").show();
		if((cur*1+1)==$("#counter").text())$(".next").hide();
	});
	return false;
 })
  $('.prev').click(function(){
	
	var prev=cur*1-1;
	var current=cur;
	$('.news-image').fadeOut('fast', function(){
		$('#img'+ current).hide();
		$('#img' + prev).show();
		$('.news-image').fadeIn('fast');
		cur=prev;
		if(cur==0) $(".prev").hide();
		$(".next").show();
	});
	cur=prev;
	return false;
 });

});
