/*if(window.Event) window.captureEvents(Event.KEYDOWN);

function keyDown(e){
  var n = (window.Event) ? e.which : e.keyCode;
  if(n==38 || n==40) return false;
}*/

// For use within normal web clients 
var isiPad = navigator.userAgent.match(/iPad/i) != null;

// For use within iPad developer UIWebView
// Thanks to Andrew Hedges!
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua)

$(document).ready(function(){
	
	$('.sliderContTxtInfo p').hide(); 
	$('.sliderContTxtInfo p:not(:has(img))').show();
	$('.service p').hide(); 
	$('.service p:not(:has(img))').show();  
	
	/*img*/
	if(!isiPad){
		$(".imgCont").hover(
		  function () {
		    $('.desp').stop(true, false).animate({ left: -467 }, {duration: 400});
		  }, 
		  function () {
		    $('.desp').stop(true, false).animate({ left: -570 }, {duration: 600});
		    desp= 0;
		  }
		);
	}else{
		$('.desp').css('left', -467);
	}
	
	var desp = 0;
	$('.desp').click(function (){
		if(desp==0){
			desp++;
			$(this).animate({ left: 0 }, {duration: 600});
		}else{
			desp--;
			$(this).animate({ left: -467 }, {duration: 600});
		}
	})
	
	$('.despCont p').hide(); 
	$('.despCont p:not(:has(img))').show(); 

	/*tooltip*/
	$(".btnGral li a[title]").tooltip({
	   offset: [2, 2],
	   effect: 'slide'
	}).dynamic({ bottom: { direction: 'down'} });
	
	/*botonera*/
	$(".btnGral li a").mouseover(function() {
		$(".btnGral li a").stop(true, false).animate({ opacity: 0.6 }, {duration: 200});
		$(this).stop(true, false).animate({ opacity: 1 }, {duration: 200});
	}).mouseout(function(){
		$(".btnGral li a").stop(true, false).animate({ opacity: 1 }, {duration: 200});
	});
	
	/*nosotros*/	
	$(".nosotros .nosotrosContact").fadeTo('fast', 0);
	$(".nosotros .nosotrosLi").mouseover(function() {
		$(this).children('.nosotrosContact').stop(true, false).fadeTo('fast', 1);
	}).mouseout(function(){
		$(this).children('.nosotrosContact').stop(true, false).fadeTo('fast', 0);
	});
	
	var i = 1;
	$('.nosotros .nosotrosLi').each(function(i) {
		$(this).addClass('nosotros'+i);
	});
	
	/*Contacto*/
	$(".contactBox").hover(
	  function () {
	    $(this).stop(true, false).animate({ bottom: -457 }, {duration: 600});
	  }, 
	  function () {
	    $(this).stop(true, false).animate({ bottom: -926 }, {duration: 600});
	  }
	);

	/*Scroll*/
	var mov = 0;
	function handle(delta) {
  
		/*Scroll Action*/
		if (delta < 0){
			if(mov==-10500){
				mov=0;
				moverDown();
			}else{
				moverDown();
			}
		}else{
			if(mov==0){
				mov=-10440;
				moverUp();
			}else{
				moverUp();
			}
		}
	};
	
	/*Scroll Top*/
	function moverUp(){
		$('.layout').css( "top", mov+=30 );
	};
	
	/*Scroll Down*/
	function moverDown(){
		$('.layout').css( "top", mov-=30 );
	};

	/*Function Scroll*/
	function wheel(event){
		var delta = 0;
		if (!event) event = window.event;
		if (event.wheelDelta) {
			delta = event.wheelDelta/120; 
			if (window.opera) delta = -delta;
		} else if (event.detail) {
			delta = -event.detail/3;
		}
		if (delta)
			handle(delta);
			if (event.preventDefault)
					event.preventDefault();
			event.returnValue = false;
	};

	/* Ini Scroll */
	if (window.addEventListener)
		window.addEventListener('DOMMouseScroll', wheel, false);
	window.onmousewheel = document.onmousewheel = wheel;

	$(".btn1").click(function () {
		mov = 0;
		destination = 0;
		$(".layout").stop(true, false).animate({ top: destination }, {duration: 2600/* ,easing:'easeOutBack' */});
		$('title').text("AED | Aquiesdonde - Agencia Digital");
		return false;
6	});
	
	$(".btn2").click(function () {
		mov = -1440;
		destination = -1440;
		$(".layout").stop(true, false).animate({ top: destination }, {duration: 2600/* ,easing:'easeOutBack' */});
		$('title').text("AED | Aquiesdonde - Hacemos - Servicios");
		return false;
	});
	
	$(".btn3").click(function () {
		mov = -3630;
		destination = -3630;
		$(".layout").stop(true, false).animate({ top: destination }, {duration: 2600/* ,easing:'easeOutBack' */});
		$('title').text("AED | Aquiesdonde - Porfolio");
		return false;
	});
	
	$(".btn4").click(function () {
		mov = -6660;
		destination = -6660;
		$(".layout").stop(true, false).animate({ top: destination }, {duration: 2600/* ,easing:'easeOutBack' */});
		$('title').text("AED | Aquiesdonde - Lab");
		return false;
	});
	
	$(".btn5").click(function () {
		mov = -8880;
		destination = -8880;
		$(".layout").stop(true, false).animate({ top: destination }, {duration: 2600/* ,easing:'easeOutBack' */});
		$('title').text("AED | Aquiesdonde - Nosotros");
		return false;
	});
	
	//Galeria Servicios
	
	var movServicios = 714;
	var infoCont = $('.sliderContTxtInfo').size();
	var sliderWidth = movServicios * infoCont;
	var count;
	var li = 0;
	var animClickLi = new Array() ;
	var countS = 0;
	$('.serviceBottom .btnL a').hide();
	$('.serviceBottom .btnL .btnLInac').show();
	$('.serviceBottom .btnR .btnRInac').hide();
	
	$('.sliderContTxtInfoCont').width(sliderWidth);
	
	//Bullets
	for (i = 0; i <= infoCont - 1; i++){
		if(i == 0){
			li = 0;
		}else{
			li = -614;
		}
		var animClick = li * i;
		animClickLi[i] = 0 + animClick ;
		countS++;
		$('.serviceBottom .bullets').append('<li class="clickGral click'+i+'" ><a href="javascript:;" title="Servicios '+countS+'"><span>btn</span></a></li>');
		$(".click0").addClass("Act");
	};

	var guardar = 0;
	
	$('.clickGral').click( function () {
		var index = $('.clickGral').index(this);
		guardar = index;
		$('.clickGral').removeClass('Act');
		$(this).addClass('Act');
		$(".sliderContTxtInfoCont").animate({ left: animClickLi[index] }, {duration: 700});
		
		if($('.clickGral:last-child').hasClass('Act')){
			$('.serviceBottom .btnR a').hide();
			$('.serviceBottom .btnR .btnRInac').show();
		}else{
			$('.serviceBottom .btnR a').show();
			$('.serviceBottom .btnR .btnRInac').hide();
		}
		
		if($('.clickGral:first-child').hasClass('Act')){
			$('.serviceBottom .btnL a').hide();
			$('.serviceBottom .btnL .btnLInac').show();
		}else{
			$('.serviceBottom .btnL a').show();
			$('.serviceBottom .btnL .btnLInac').hide();
		}
		
	});
	
	//BtnR
	$('.serviceBottom .btnR a').click( function () {
		$('.serviceBottom .btnL .btnLInac').hide();
		$('.sliderContTxtInfoCont').animate({ left: animClickLi[guardar] -614 }, {duration: 700});
		
		guardar ++;
		$('.clickGral').removeClass('Act');
		$('.clickGral').eq(guardar).addClass('Act');
		if(guardar!= 0){
			$('.serviceBottom .btnL a').show();
			$('.serviceBottom .btnL .btnLInac').hide();
		}
		if(guardar == infoCont-1){
			$('.serviceBottom .btnR a').hide();
			$('.serviceBottom .btnR .btnRInac').show();
		}
	});
	
	//BtnL
	$('.serviceBottom .btnL a').click( function () {
		
		$('.sliderContTxtInfoCont').animate({ left: animClickLi[guardar] +614 }, {duration: 700});
		
		guardar --;
		$('.clickGral').removeClass('Act');
		$('.clickGral').eq(guardar).addClass('Act');
		if(guardar== 0){
			$('.serviceBottom .btnL a').hide();
			$('.serviceBottom .btnL .btnLInac').show();
		}
		if(guardar != infoCont-1){
			$('.serviceBottom .btnR a').show();
			$('.serviceBottom .btnR .btnRInac').hide();
		}
	});
	
	//Galeria Imagenes
	
	var movImages = 804;
	var infoContImage = $('.imageSlide img').size();
	var sliderWidthImage = movImages * infoContImage;
	var li = 0;
	var animClickLiImage = new Array() ;
	var count = 0;
	
	$('.proyect .btnL').hide();
	$('.btnRInac').hide();
	
	$('.despCont').hide();
	$('.despCont').eq(0).show();
	
	$('.imageSlide').width(sliderWidthImage);
	
	//Bullets
	for (i = 0; i <= infoContImage - 1; i++){
		if(i == 0){
			li = 0;
		}else{
			li = -804;
		}
		var animClickImage = li * i;
		animClickLiImage[i] = 0 + animClickImage ;
		count++;
		
		$('.proyect .bullets').append('<li class="clickGral click'+i+'" ><a href="javascript:;" title="Destacado '+count+'"><span>btn</span></a></li>');
		$(".proyect .click0").addClass("Act");
	};
	
	var guardarImg = 0;
	
	$('.proyect .clickGral').click( function () {
		var index = $('.proyect .clickGral').index(this);
		guardarImg = index;
		$('.proyect .clickGral').removeClass('Act');
		$(this).addClass('Act');
		$(".imageSlide").animate({ left: animClickLiImage[index] }, {duration: 700});
	
		$('.despCont').hide();
		$('.despCont').eq(index).show();
	
		if($('.proyect .clickGral:last-child').hasClass('Act')){
			$('.proyect .btnR').hide();
			$('.btnRInac').show();
		}else{
			$('.proyect .btnR').show();
			$('.btnRInac').hide();
		}
		
		if($('.proyect .clickGral:first-child').hasClass('Act')){
			$('.proyect .btnL').hide();
			$('.btnLInac').show();
		}else{
			$('.proyect .btnL').show();
			$('.btnLInac').hide();
		}
		
	});
	
	//BtnR
	$('.proyect .btnR').click( function () {

		$('.imageSlide').animate({ left: animClickLiImage[guardarImg] -804 }, {duration: 700});
		
		guardarImg ++;
		
		$('.btnRInac').hide();
		
		$('.despCont').hide();
		$('.despCont').eq(guardarImg).show();
		
		
		$('.proyect .clickGral').removeClass('Act');
		$('.proyect .clickGral').eq(guardarImg).addClass('Act');
		if(guardarImg!= 0){
			$('.proyect .btnL').show();
			$('.btnLInac').hide();
		}
		if(guardarImg == infoContImage-1){
			$('.proyect .btnR').hide();
			$('.btnRInac').show();
		}
	});
	
	//BtnL
	$('.proyect .btnL').click( function () {
		
		$('.imageSlide').animate({ left: animClickLiImage[guardarImg] +804 }, {duration: 700});
		
		guardarImg --;
		
		$('.despCont').hide();
		$('.despCont').eq(guardarImg).show();
		
		
		$('.proyect .clickGral').removeClass('Act');
		$('.proyect .clickGral').eq(guardarImg).addClass('Act');
		if(guardarImg== 0){
			$('.proyect .btnL').hide();
			$('.btnLInac').show();
		}
		if(guardarImg != infoContImage-1){
			$('.proyect .btnR').show();
			$('.btnRInac').hide();
		}
	});
	
})

if(isiPad){
	
	$(document).ready(function(){
		$(body).width(1024);
	});
	
	$(window).scroll(function() {
		//header
		//$(".hd").css('display', 'none');
		//$(".hd").css('position', 'absolute');
		//var y = $(window).scrollTop();
		//$(".hd").css('top', y);
		
		//contact
		$(".contactBox").css('display', 'none');
		//var y = $(window).scrollTop();
		//$(".contactBox").css('bottom', y-60);
	});
	
	$('.sliderContTxtInfoCont').bind("touchstart touchmove", function(e) {
		$(this).animate({ left: 614 }, {duration: 700});
	});
	
	$('body').bind("touchmove", function(e) {
		$(".hd").hide();
	});
	
	$('body').bind("touchend", function(e) {
		$(".hd").show();
	});

}

//Google Maps
function initialize() {
	if (GBrowserIsCompatible()) {
		//$('.mapas').css('visibility','hidden');
		var map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(-34.6226058, -58.399676), 16);
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		//
		var icono = new GIcon();
		icono.image = 'http://aquiesdonde.com.ar/site2011/wp-content/themes/v1/img/Comun/lg_maps.png';
		icono.shadow = 'http://aquiesdonde.com.ar/site2011/wp-content/themes/v1/img/Comun/lg_MapsSombra.png';
		icono.size = new GSize(72,53);
		icono.shadowSize = new GSize(97,53);
		icono.iconAnchor = new GPoint(11,40);
		icono.infoWindowAnchor = new GPoint(11,0);
		var iconoPoint = new GLatLng(-34.622158, -58.403291);
		//
		function createMarker(point,icon,textoHtml){
			markerOptions = { icon:icon };
			var marker = new GMarker(point, markerOptions);
			if(textoHtml){
				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(textoHtml);
				});
			}
			return marker;
		}
		map.addOverlay(createMarker(iconoPoint,icono,"<strong>AED: Aquiesdonde</strong><br />Humberto I&deg; 2735 - San Cristobal<br />C1231ACC - Buenos Aires Argentina.<br 7>+ 5411 4943-0717"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		//map.addControl(new GOverviewMapControl());

	}
};
/*$(document).bind("touchstart touchmove", function(e) {
	$(".gralNav").fadeTo("fast", 0);
});*/


