var map;
var arrMarkers = [];
var arrInfoWindows = [];
	
function initialize() {
	var latlng = new google.maps.LatLng(54.32933804825253, -2.6806640625);
	var myOptions = {
		zoom: 6,
		center: latlng,
		scrollwheel: false,
		navigationControl: false,
		mapTypeControl: false,
		scaleControl: false,
		draggable: true,
		streetViewControl: false,
		mapTypeId: google.maps.MapTypeId.TERRAIN
	};
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var image = mainDom+"/template/images/mapIcon.png";

	$.each(json.Loc, function(i, item){
		var marker = new google.maps.Marker({
			position: new google.maps.LatLng(item.lat, item.lng),
			map: map,
			title: item.title,
			icon: image
		});
		arrMarkers[i] = marker;
		var infowindow = new google.maps.InfoWindow({
			disableAutoPan: false,
			content: "<span class='gm-title'>"+ item.title +"</span><span class='gm-desc'>"+ item.description +"</span>"
		});
		arrInfoWindows[i] = infowindow;
		google.maps.event.addListener(marker, 'click', function() {
			for(x=0; x < arrInfoWindows.length; x++){ arrInfoWindows[x].close(); }
			infowindow.open(map, marker);
		});
	});
}
function ajaxForm() {
	var str = $("#form").serialize();
	$.get(
		mainDom+"/scripts/ajax.php",
		str,
		function(data) { $("#CART").html(data); },
		"html"
	)  
}

function closedDays(date) {
	for (i = 0; i < clDays.length; i++) {
	  if (date.getFullYear() == clDays[i][0] && date.getMonth() == clDays[i][1] - 1 && date.getDate() == clDays[i][2]) {
		if(clDays[i][3] == "full") {
			return [false, 'full', 'Full'];
		}else{
			return [false, '', 'Closed'];
		}
	  }
	}
  return [true, ''];
}
function mainmenu(){
$(".menu ul ul").css({display: "none"}); // Opera Fix
$(".menu ul li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}



$(document).ready(function() {

	mainmenu();
	
	$(".ajax").change(ajaxForm);

	$("#btnAdd").click(function() {
		var num = $('.clonedInput').length;
		var newNum = new Number(num + 1);
		var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
		newElem.find('.name').attr('id', 'name' + newNum).attr('name', 'name[' + newNum + ']').attr('value', '');
		newElem.find('.weightS').attr('id', 'weightS' + newNum).attr('name', 'weightS[' + newNum + ']').attr('value', '');
		newElem.find('.heightF').attr('id', 'heightF' + newNum).attr('name', 'heightF[' + newNum + ']').attr('value', '');
		newElem.find('.weightL').attr('id', 'weightL' + newNum).attr('name', 'weightL[' + newNum + ']').attr('value', '');
		newElem.find('.heightI').attr('id', 'heightI' + newNum).attr('name', 'heightI[' + newNum + ']').attr('value', '');
		newElem.find('.age').attr('id', 'age' + newNum).attr('name', 'age[' + newNum + ']').attr('value', '');
		newElem.find('.sex').attr('id', 'sex' + newNum).attr('name', 'sex[' + newNum + ']').attr('value', '');
		newElem.children('.title').text('Jumper ' + newNum);
		$('#input' + num).after(newElem);
		$('#btnDel').removeAttr('disabled');
		ajaxForm();
	});

	$('#btnDel').click(function() {
		var num = $('.clonedInput').length;
		$('#input' + num).remove();
		if (num-1 == 1) { $('#btnDel').attr('disabled','disabled'); }
		ajaxForm();
	});
	if($(".lightbox").length > 0){
		$(".lightbox").lightbox({ fitToScreen: true, scaleImages: true });
	}
	if($(".rotator").length > 0){
		theRotator();
	}
	if($("#map_canvas").length > 0){
		initialize();
	}
	if($(".formRight").length > 0){
		$(".select").datepicker({ beforeShowDay: closedDays, numberOfMonths: 2, showButtonPanel: true, minDate: "+1d", maxDate: "+1y", altField: "#altDate", altFormat: "@", dateFormat: "dd/mm/yy"});
	}
	if($("#place-slider").length > 0){
		$('#place-slider').nivoSlider({
			effect: 'fade',
			animSpeed: 400,
			pauseTime: 6000,
			directionNav: false
		});
	}

	
    $('input#billCopy').click(function() {
        if ($(this).attr('checked')){
            $('#billingDetails td input:text').each(function(i) {
				$(this).val($('#shippingDetails td input:text').eq(i).val());
				var billState = $("select#billState").val();
				$('select#shipState option[value=' + billState + ']').attr('selected', 'selected');
            });
        }else{
			$('#billingDetails td input:text').each(function(i) {
				$(this).val("");
				$('select#shipState option[value=""]').attr('selected', 'selected');
			});
		}
    });
	
	$(".twitter-plugin").tweet({
		username: "jumpwithus",
		join_text: "auto",
		avatar_size: 0,
		count: 1,
		auto_join_text_default: "we said,",
		auto_join_text_ed: "we",
		auto_join_text_ing: "we were",
		auto_join_text_reply: "we replied to",
		auto_join_text_url: "we were checking out",
		loading_text: "loading tweets..."
    });
	
	$('#shareme').sharrre({
share: {
googlePlus: true,
facebook: true,
twitter: true,
digg: true,
delicious: true
},
enableTracking: true,
buttons: {
googlePlus: {size: 'tall'},
facebook: {layout: 'box_count'},
twitter: {count: 'vertical'},
digg: {type: 'DiggMedium'},
delicious: {size: 'tall'}
},
hover: function(api, options){
$(api.element).find('.buttons').show();
},
hide: function(api, options){
$(api.element).find('.buttons').hide();
}
});
}); 
