/* Logging */
window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){arguments.callee=arguments.callee.caller;var a=[].slice.call(arguments);(typeof console.log==="object"?log.apply.call(console.log,console,a):console.log.apply(console,a))}};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());

/*
 * JCarousel
 * 
 */
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {


$('#quickbook').submit(function() {
	var hotelnumber = $('select.hotel option:selected').val();
	var children= $('input.child').val();
	var adults= $('input.adult').val();
	var arrive= $('input.arrive').val();
	var depart= $('input.depart').val();
	var start= 'availresults'
	callBookingFrame(hotelnumber, children, adults, arrive, depart, start);
  return false;
});

// Manual booking link - only if title="Booking"
$("a[title='Booking'],a[title='booking']").each(function() {
	var href = $(this).attr('href');
	$(this).attr('href', 'javascript:void(0)');
	$(this).click(function() {
		callBookingFrame(null, null, null, null, null, null, href)
		return false;
	});
});
$("img[alt='Booking'],img[alt='booking']").each(function() {
	if($(this).parent().attr('href')) {
		var href = $(this).parent().attr('href');
		$(this).parent().attr('href', 'javascript:void(0)');
		$(this).parent().click(function() {
			callBookingFrame(null, null, null, null, null, null, href)
			return false;
		});
	}
});
/*
$('a[title="Booking"]').click(function() {
	
	return false;
});
*/

    jQuery('#mycarousel').jcarousel({
        auto: 5,
        scroll: 1,
        wrap: 'circular',
        animation: 1000,
        buttonNextHTML: '<a href="#" id="frontPageSliderButtonRight"><!-- --></a>',
        buttonPrevHTML: '<a href="#" id="frontPageSliderButtonLeft"><!-- --></a>'
    });
});

// shop accept
function shop_accept(me) {
	/*
	if(me.checked) {
		$('#submit3').each(function(a, b) {
			b.disabled='';
		});
	} else {
		$('#submit3').each(function(a, b) {
			b.disabled='disabled';
		});
	}
	*/
}
$(document).ready(function() {
	$('.findInnRegionDropdown, input[name="fritekst"]').focus(function() {
		this.select();
	});
	$('#submit3').each(function(a, b) {
		b.disabled='';
	});
	$('#submit3').click(function() {
		if($('#shopAcceptCheck').attr('checked')) {
			return true;
		} else {
			alert('Du skal acceptere handelsbetingelserne før du kan gå til kassen.');
			return false;
		}
		return false;
	});
	/*
	$('#submit3').click(function() {
		¨//window.console.log($('#shopAcceptCheck'));
		if($('#shopAcceptCheck').value) {
			alert('test');
		} else {
			alert('test2');
		}
		return false;
	});
	*/
});

function shop_delete(id) {
	if(confirm('Er du sikker på at du vil slette produktet fra indkøbskurven?')) {
		$('#del_product_id').val(id);
		//window.console.log($('#del_product_id'));
		$('#delForm').submit();
		}
}

// Ride the carousel...
$(document).ready(function() {
	
	$('#separatedelivery').change(function() {
		$("#deliveryinfo").slideToggle('fast');
		//return false;
	});
	$('#notseparatedelivery').change(function() {
		$("#deliveryinfo").slideToggle('fast');
		//return false;
	});
	
	$('#relatedCancel').click(function() {
		$('.alert_related_products_bg').hide('fast');
		$('.alert_related_products').hide('fast');
	});
	
	if ($('#header').length ) {
		$('#header').cycle();
	}

	$('a#webcode').click(function() {
		if($(this).hasClass('logout')) {
			// Smadre session cookie!
			// @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
			//$.cookie('sid', null);
			var host = $('#defaultInformation div.http_host').html().replace('www.','');
			$.cookie('sid', null, {path: '/', domain: host});
			document.location = "/";
		} else {
			$("#dialog").slideDown("fast");
		}
		return false;
	});


	$('a[rel=booknow]').click(function() {
		/*
		var hotelnumber = $(this).attr('id');
		var language = $(this).attr('lang');
		$("#bookingiframe").html('<iframe src="https://gc.synxis.com/rez.aspx?Hotel=' + hotelnumber + '&Chain=12142&template=2&locale=' + language + '" frameBorder="0" marginheight="0" marginwidth="0" scrolling="auto" title="Booking" id="bookingIframerInner"></iframe>');
		*/
		callBookingFrame($(this).attr('id'));
		//$("#booking").fadeIn('fast');
		return false;
	});

	$('a#btnBooking').click(function() {
		/* Gammel funktionalitet marked out
		var language = $(this).attr('lang');
		$("#bookingiframe").html('<iframe src="https://gc.synxis.com/rez.aspx?Chain=12142&template=2&locale=' + language + '" frameBorder="0" marginheight="0" marginwidth="0" scrolling="auto" title="Booking" id="bookingIframerInner"></iframe>');
		$("#booking").fadeIn('fast');
		*/
		callBookingFrame();
		return false;
	});
	$('a#btnMemberBooking').click(function() {
		callBookingFrame($(this).attr('name')); //Kaldet til den ny funktion
		/* gammel funktionalitet marked out
		callBookingFrame($(this).attr('name'));
		var hotelnumber = $(this).attr('name');
		var language = $(this).attr('lang');
		$("#bookingiframe").html('<iframe src="https://gc.synxis.com/rez.aspx?Hotel=' + hotelnumber + '&Chain=12142&template=2&locale=' + language + '" frameBorder="0" marginheight="0" marginwidth="0" scrolling="auto" title="Booking" id="bookingIframerInner"></iframe>');
		$("#booking").fadeIn('fast');
		*/
		return false;
	});
	$('a#btnBookingClose').click(function() {
		$("#booking").fadeOut('fast');
		$("#bookingiframe").html("");		
		return false;
	});

/*	
	function callBookingFrame(hotel) {
		var basisURL = 'https://gc.synxis.com/rez.aspx?Chain=12142';
		var template = 2;
		if(hotel) {
			basisURL = basisURL + '&Hotel='+hotel;
		}
		basisURL = basisURL + "&template="+$('#defaultInformation div.templateId').html();
		basisURL = basisURL + "&locale="+$('#defaultInformation div.locale').html();
		if($('#defaultInformation div.sxCode').length > 0) {
			basisURL = basisURL + "&IATA="+$('#defaultInformation div.sxCode').html();
		}
		_gaq.push(function() {
			var pageTracker = _gat._getTrackerByName();
			var myFrame = document.createElement('iframe');
			myFrame.id = "bookingIframeInner";
			myFrame.src = pageTracker._getLinkerUrl(basisURL);
			myFrame.setAttribute('frameborder', 0);
			myFrame.setAttribute('marginheight', 0);
			myFrame.setAttribute('marginwidth', 0);
			myFrame.setAttribute('scrolling', 'auto');
			myFrame.setAttribute('title', 'Booking');
			$("#bookingiframe").html(myFrame);
			$("#booking").fadeIn('fast');
		});
	}

*/	
	$('a#dialogclose').click(function() {
		$("#dialog").slideUp("fast");
		return false;
	});
	
	if ($('input.date-pick').length ) {
		// $('.date-pick').datePicker().val(new Date().asString()).trigger('change');
		$('.date-pick').datePicker();
		$('#start-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#end-date').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#end-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#start-date').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
}



if ($('#membergooglemap').length ) {
		initialize();
	}

	if ($('#memberImage').length ) {
		 $('#memberImage').galleria({
				image_crop: false,
				transition: 'fade',
				autoplay: true,
				carousel_follow: true
			});
	}
	if ($('#product-image').length ) {
		 $('#product-image').galleria({
				image_crop: true,
				transition: 'fade',
				autoplay: true,
				carousel_follow: true
			});
	}
});
function callBookingFrame(hotel, child, adult, arrival, departure, start, basisURL) {
	if(!basisURL) basisURL = 'https://gc.synxis.com/rez.aspx?Chain=12142';
	
	// var template = 2;
	var template = '';
	
	if(hotel) {
		basisURL = basisURL + '&Hotel='+hotel;
	}
	//basisURL = basisURL + "&template="+$('#defaultInformation div.templateId').html().replace('<!---->', '');
	if($('#defaultInformation div.templateId').length > 0) {
		basisURL = basisURL + "&template="+$('#defaultInformation div.templateId').html();
	} else {
		basisURL = basisURL + "&template=GCOPS";
	}
	basisURL = basisURL + "&locale="+$('#defaultInformation div.locale').html();
	if($('#defaultInformation div.sxCode').length > 0) {
		basisURL = basisURL + "&IATA="+$('#defaultInformation div.sxCode').html();
	}
	if($('#defaultInformation div.guestMail').length > 0) {
		basisURL = basisURL + "&guestEmail="+$('#defaultInformation div.guestMail').html();
	}
	if($('#defaultInformation div.site').length > 0) {
		basisURL = basisURL + "&shell="+$('#defaultInformation div.site').html();
		if($('#defaultInformation div.locale').html() == 'en-UK') basisURL = basisURL + 'Eng';
	}
	
	// Hvis et ID er sat, så redirecter vi til den side.
	if($('#defaultInformation div.bookingPageID').length > 0) {
		document.location = "/via"+$('#defaultInformation div.bookingPageID').html()+'.html';
		return false;
	}
	
	// QuickBook specific
	if(child) basisURL = basisURL + "&child="+child;
	if(adult) basisURL = basisURL + "&adult="+adult;
	if(arrival) basisURL = basisURL + "&arrive="+arrival;
	if(departure) basisURL = basisURL + "&depart="+departure;	
	if(start) basisURL = basisURL + "&start="+start;	

	//console.debug("Basisurl=", basisURL);
	if(typeof(_gaq) != 'undefined') {
		var pageTracker = _gat._getTrackerByName();
		_gaq.push(['_setDomainName', 'none']);
		_gaq.push(['_setAllowLinker', true]);
		pageTracker._link(basisURL);
	} else {
		document.location.href=basisURL;
	}
	
	/*
if(typeof(_gaq) != 'undefined') {
		_gaq.push(function() {
			var pageTracker = _gat._getTrackerByName();
			var myFrame = document.createElement('iframe');
			myFrame.id = "bookingIframeInner";
			myFrame.src = pageTracker._getLinkerUrl(basisURL);
			myFrame.setAttribute('frameborder', 0);
			myFrame.setAttribute('marginheight', 0);
			myFrame.setAttribute('marginwidth', 0);
			myFrame.setAttribute('scrolling', 'auto');
			myFrame.setAttribute('title', 'Booking');
			$("#bookingiframe").html(myFrame);
			$("#booking").fadeIn('fast');
		});
	} else {
		var myFrame = document.createElement('iframe');
		myFrame.id = "bookingIframeInner";
		myFrame.src = basisURL;
		myFrame.setAttribute('frameborder', 0);
		myFrame.setAttribute('marginheight', 0);
		myFrame.setAttribute('marginwidth', 0);
		myFrame.setAttribute('scrolling', 'auto');
		myFrame.setAttribute('title', 'Booking');
		$("#bookingiframe").html(myFrame);
		$("#booking").fadeIn('fast');
	}
*/
}
