﻿function moveVert() {
	height = $("#wrapper").height();
	winheight = $(window).height();
	if(height < winheight) {
		margin = ( winheight - height) / 2;
	} else {
		margin = 20;
	}
	$("#wrapper").css("marginTop", margin + "px");
	$("#mainmenu").css("margin-left", 0 + "px");
}

function showofertas(){
	repairBlack();
	$("#contactBlack").fadeTo("medium", 0.3);
	$("#ofertas").fadeIn("medium");
}

function techfeat(){
	$(".feat").fadeOut("medium");
	$("#techfeat").fadeIn("medium");
	hidevideo();
}
function equip(){
	$(".feat").fadeOut("medium");
	$("#equip").fadeIn("medium");
	hidevideo();
}
function video(){
	$(".feat").hide(0, function(){$(".mainpic").hide(0);});
	$("#videos").show(0);
}
function hidevideo(){
	$(".mainpic").show(0);
	$("#videos").hide(0);
}
$(document).ready(function() {
	$(".closeofofe").click(function(){ $("#ofertas").fadeOut(); $("#contactBlack").fadeOut() });
	$(".closeofcon").click(function(){
		clearErrors();
		$("#contact").fadeOut();
		$("#contactBlack").fadeOut();
		$('input[type=checkbox]').attr('checked', false);
	});
	$(window).resize(function() { moveVert()
	});
	sly = 0;
	$('#socialdiv img').each(function() {
		$(this).delay(sly).fadeTo('medium', 0.7);
		sly += 200;
		$(this).hover(function() {
			$(this).fadeTo('medium', 1);
		}, function() {
			$(this).fadeTo('medium', 0.5);
		});
	});
    $(".mainmenuli").each( function(){ $(this).hover(
        function(){ 
            $(".menudesp", this).fadeTo("normal", 0.9);
        },
        function(){
            $(".menudesp", this).hide();
        }
    );});
	/* Partes especificas de apartados concretos */
	// Apartado de productos
	if(document.page == "productos") {
		$(".next:first").addClass("active");
		
		techfeat();
		var $galeria = $('a[rel=galeria]').colorbox({transition:"fade"})
        $('a#galeria').click(function(e){
            e.preventDefault(); 
            $galeria.eq(0).click(); 
        });
		$(".pi .array:first-child").show();

		num = 0;
		$(".pi .array").each( function(){
			$(this).addClass("sh"+num);
			num++;
		})
		num = 0;
		$(".next").each( function(){
			$(this).addClass("sh"+num);
			num++;
			$(this).click( function(){
				a = $(this).attr("class").split(' ');
				if(a.length < 3){
					for(i=0; i<a.length; i++){
						if(a[i] != "next"){
							defclass = a[i]
						}
					}
					$(".array").hide(800);
					$(".pi").find("."+defclass).show(800);
					$(".next").removeClass("active");
					$(this).addClass("active");
					a = $(".next").index(this);
					$("#numpag").html(a+1);
				}
			});
		})
	}
	// Página de nauticos
	if(document.page == "nauticos") {
		$(".smallprod").fadeTo(1, 0.7);
		$(".smallprod").hover(
			function(){ $(this).fadeTo("normal", 1); },
			function(){ $(this).fadeTo("normal", 0.7); }
		)
		$(".smallprod").click( function(){
			num = $(this).attr("id").split('-');
			$(".hugeprod:visible").css("display", "none");
			$("#bg-"+num[1]).fadeIn();
		});
	}
	// Página de noticias
	if(document.page == "noticias") {
		
		limit = 0;
		if($(".blocknew").length>3){
			$(".nex").fadeIn("medium");
			limit = -1;
			if($(".blocknew").length>6) {limit = -952;}
		}
		if($(".firstone").length!=0){
			$(".pre").fadeIn("medium");
			link = $(".firstone").attr("href");
			$(".pre").attr("href", link);
		}
		$(".nex").click(function(){
			actMarg = parseInt($(".newshider").css("margin-left"));
			$(".pre").attr("href", "javascript:void(0)");
			if(actMarg > -1900){
				$(".newshider").animate({marginLeft: '-=951'}, 800)
				$(".pre").fadeIn("medium");
				if(actMarg-951 < limit) {
					if($(".lastone").length==0){
						$(".nex").fadeOut();
					}
				}
			} else {
				link = $(".lastone").attr("href");
				$(".nex").attr("href", link);
			}
		});
		$(".pre").click(function(){
			actMarg = parseInt($(".newshider").css("margin-left"));
			$(".nex").attr("href", "javascript:void(0)");
			if(actMarg < 0){
				$(".newshider").animate({marginLeft: '+=951'}, 800)
				$(".nex").fadeIn("medium");
				if(actMarg+951 > -949){
					if($(".firstone").length==0){
						$(".pre").fadeOut();
					}
				}
			} else {
				link = $(".firstone").attr("href");
				$(".pre").attr("href", link);
			}
		});
	}
	if(document.page == "mapa") {
		googlemapsload();
	}
	activForm();
});

function googlemapsload() {
    var myOptions = {
      zoom: 12,
      center: new google.maps.LatLng(43.276734, -2.061853),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("mapa"),myOptions);
 
    var image = '/static/img/astgmicon.png';
    var FirstLatLng = new google.maps.LatLng(43.26500, -2.061853);
	var SecondLatLng = new google.maps.LatLng(41.431112,2.104206);
	var ThirdLatLng = new google.maps.LatLng(41.467516,-2.009666);
	var ForthLatLng = new google.maps.LatLng(37.189109,-1.82682);
    var beachMarker1 = new google.maps.Marker({
        position: FirstLatLng,
        map: map,
        icon: image
    });
	var infowindow1 = new google.maps.InfoWindow({
        content: "<div style='font-size: 13px; width: 300px; font-family: arial'><p><b>NORAIA NÁUTICA, S.L.</b></p><p>Barrio Inchaurreta, s/n - Ap. 6</p><p>20170, Aguinaga-Usurbil (Guipúzcoa)</p><p>Teléfono: 94 364 59 35</p><p>Fax: 94 336 26 60</p><p>Email: info@noraianautika.com</p><p><a href='http://www.noraianautika.com' target='_blank'>www.noraianautika.com</a></p></div>"
    });
    var beachMarker2 = new google.maps.Marker({
        position: SecondLatLng,
        map: map,
        icon: image
    });
	var infowindow2 = new google.maps.InfoWindow({
        content: "<div style='font-size: 13px; width: 300px; font-family: arial'><p><b>CHARTERS VILANOVA, S.L.</b></p><p>P.I. Rubi Sur - Av. Antonio Gaudi s/n, Nave 10</p><p>08191 - Rubí (Barcelona)</p><p>Teléfono: 93 588 08 28 - Móvil: 607 514 201</p><p>Fax: 93 588 00 95</p><p>Email: info@astillerosplayamar.com</p><p><a href='/' target='_blank'>www.astillerosplayamar.com</a></p></div>"
    });
    var beachMarker3 = new google.maps.Marker({
        position: ThirdLatLng,
        map: map,
        icon: image
    });
	var infowindow3 = new google.maps.InfoWindow({
        content: "<div style='font-size: 13px; width: 300px; font-family: arial'><p><b>NAUTICA GUARDAMAR, S.L.</b></p><p>Avda. del Puerto, s/n - Ap. 21</p><p>03140, Guardamar (Alicante)</p><p>Tel/Fax: 96 672 58 88</p><p>Móvil: 667 660 482</p><p>Email: nauticaguardamar@hotmail.com</p></div>"
    });
    var beachMarker4 = new google.maps.Marker({
        position: ForthLatLng,
        map: map,
        icon: image
    });
	var infowindow4 = new google.maps.InfoWindow({
        content: "<div style='font-size: 13px; width: 300px; font-family: arial'><p><b>EFECTO NAVALES ANDRES, S.L.</b></p><p>Explanada Puerto Pesquero</p><p>04630, Garrucha (Almeria)</p><p>Teléfono: 950 132 538</p><p>Móvil: 670 589 310</p><p>Email: garrucha007@hotmail.es</p></div>"
    });
    google.maps.event.addListener(beachMarker1, 'click', function() {
      infowindow1.open(map,beachMarker1);
    });
    google.maps.event.addListener(beachMarker2, 'click', function() {
      infowindow2.open(map,beachMarker2);
    });
    google.maps.event.addListener(beachMarker3, 'click', function() {
      infowindow3.open(map,beachMarker3);
    });
    google.maps.event.addListener(beachMarker4, 'click', function() {
      infowindow4.open(map,beachMarker4);
    });
    infowindow1.open(map,beachMarker1);
	$(".open1").click( function() { map.setCenter(FirstLatLng) });
	$(".open2").click( function() { map.setCenter(SecondLatLng) });
	$(".open3").click( function() { map.setCenter(ThirdLatLng) });
	$(".open4").click( function() { map.setCenter(ForthLatLng) });
}

function activeSch(id){
	repairBlack();
	$("#contactBlack").fadeTo(500, 0.6);
	$("#contact").fadeIn(function(){
		if(id != -1){
			$("input[value="+id+"]").attr('checked', true);
		}
	});
}
function repairBlack(){
	h = parseInt($('#wrapper').height()) + parseInt($('#wrapper').css('marginTop')+50);
	hwin = parseInt($(window).height());
	if(h<hwin){ h = hwin }
	$('#contactBlack').css({height : h+"px"});
}
