intDetailPhotoCounter = -1;
intDetailPhotoTimeout = 7000;
$(document).ready(function() {
    $('.pricerow .rowsubtitleextrainfo').click(function(event) {
        objExtraInfo = $(this).parent().find('.extrainfo');
        if (objExtraInfo.css('display') == 'none') {
            objExtraInfo.slideDown(200);
            $('.plusminus', this).attr('class', 'plusminus minus');
        } else {
            $('.plusminus', this).attr('class', 'plusminus plus');
            objExtraInfo.slideUp(200);
        }
        event.stopPropagation();
    });
    
    if ($('.photogroups .photogroup').length > 0) {
        $('.photogroups .photogroup>.title').each(function(intIndex) {
            $('DIV.photogroupbuttons').append('<a class="photogroupbutton">' + $(this).html() + '</a>');
        });
        $('.photogroups').each(function(intIndex) {
            objPhoto = $('.photogroup:first-child .photo:first', this);
            strImage = $('a.largephotohidden', objPhoto).attr('href');
            strTitle = $('.title', objPhoto).html();
            $('img', objPhoto).attr('class', 'selected');
            $(this).parent().find('.largephoto .photo').html('<img src="' + strImage + '" alt="" /><div class="title">' + strTitle + '</div>');
        });
        $('.photogroupbuttons .photogroupbutton').click(function() {
			intIndex = $(this).prevAll().length;
			detailActivatePhotogroup(intIndex);
        });
		if ($('.photogroupbuttons .photogroupbutton').length == 4) {
	        $('.photogroupbuttons .photogroupbutton:last-child').attr('class', 'photogroupbutton lastbutton');
		} else {
	        $('.photogroupbuttons .photogroupbutton:last-child').after('<div class="endseparator"><!----></div>');
		}
        $('.photogroupbuttons .photogroupbutton:first-child').attr('class', 'photogroupbutton firstbutton');
        $('.photogroup .photo').click(function() {
            if ($('img', this).attr('class') == 'selected') return;
            $('.photogroup .photo .selected').removeAttr('class');
            strTitle = $('.title', this).html();
            strImage = $('a.largephotohidden', this).attr('href');
            $('img', this).attr('class', 'selected');
            objLarge = $(this).parent().parent().prevAll('.largephoto');
            $('.title', objLarge).slideUp(100, function() {
                $('img', objLarge).fadeOut(200, function() {
                    $(this).attr('src', strImage);
                    if (strTitle != '') $('.title', objLarge).html(strTitle).slideDown(400);
                }).fadeIn(100);
            });
        });
        $('.photogroup').mouseover(function() {
            if (intDetailPhotoCounter > 0) {
                clearTimeout(intDetailPhotoCounter);
                intDetailPhotoCounter = -1;
            }
        }).mouseout(function() {
            if (intDetailPhotoCounter == -1) {
                intDetailPhotoCounter = setTimeout('detailPhotoNext()', intDetailPhotoTimeout);
            }
        });
    }
    $('A[href=#themes]').click(function(event) {
        intTop = $('A[name=themes]').offset().top;
        if (intTop > 0) {
            $('html').animate({scrollTop: intTop}, 200);
            event.preventDefault();
        }
    });
	$('.block.menu div > ul > li > a').click(function() {
		$('.block.menu div > ul > li > a').removeClass('selected');
		$(this).addClass('selected');
	});
	detailActivatePhotogroup(0);
	intDetailPhotoCounter = setTimeout('detailPhotoNext()', intDetailPhotoTimeout);
});

function detailActivatePhotogroup(intIndex) {
	$('.photogroupbuttons .photogroupbutton:not(eq(' + intIndex + '))').removeClass('selected');
	$('.photogroupbuttons .photogroupbutton:eq(' + intIndex + ')').addClass('selected');
	
	$('.photogroups .photogroup:not(eq(' + intIndex + '))').hide();
	$('.photogroups .photogroup:eq(' + intIndex + ')').show();
	if (intDetailPhotoCounter > 0) {
		clearTimeout(intDetailPhotoCounter);
		intDetailPhotoCounter = setTimeout('detailPhotoNext()', intDetailPhotoTimeout);
	}
}

function detailPhotoNext() {
	objSelected = $('.photogroup .photo .selected');
    objPhotoGroup = objSelected.parent().parent();
	blnDisableTimer = false;
	if (objPhotoGroup.css('display') == 'none') {
        objPhotoGroup = objPhotoGroup.parent().find('.photogroup:visible');
        objNext = objPhotoGroup.find('.photo:eq(0)');
    } else {
        objNext = objSelected.parent().next();
        if ($('.photo', objPhotoGroup).length <= 1) {
            intDetailPhotoCounter = -1;
            return;
        }
        if (objNext.length == 0) {
            blnDisableTimer = true;
			intIndex = objPhotoGroup.prevAll().length;
            intIndex++;
			if ($('.photogroups .photogroup:eq(' + intIndex + ')').length == 0) intIndex = 0;
			detailActivatePhotogroup(intIndex);
			objPhotoGroup = $('.photogroups .photogroup:eq(' + intIndex + ')');
			objNext = objPhotoGroup.find('.photo:eq(0)');
		}
    }
    objSelected.removeAttr('class');
    strTitle = $('.title', objNext).html();
    strImage = $('a.largephotohidden', objNext).attr('href');
    $('img', objNext).attr('class', 'selected');
    objLarge = $(objNext).parent().parent().prevAll('.largephoto');
    $('.title', objLarge).slideUp(100, function() {
        $('img', objLarge).fadeOut(200, function() {
            $(this).attr('src', strImage);
            if (strTitle != '') $('.title', objLarge).html(strTitle).slideDown(400);
        }).fadeIn(100);
    });
	if (!blnDisableTimer) intDetailPhotoCounter = setTimeout('detailPhotoNext()', intDetailPhotoTimeout);
}

function openGoogleMap(strUrl) {
    // Remove after go live.
    alert('Function (openGoogleMap) should not be used anymore');
}

var strDetailUrl;
function dtGetPegasusAllocation(strUrl, strDetailPageUrl){
    strDetailUrl = strDetailPageUrl;
    ajaxLoadRequest(strUrl, dtShowAllocation);
}

function dtShowAllocation(strData) {

    if (strData) {
        var arrResponse   = strData.split(";");
        var intCount;
        var arrProperties = new Array();
        var arrTemp       = new Array();
        for(intCount = 0; intCount < arrResponse.length; intCount++) {
            arrTemp = arrResponse[intCount].split(":");
            arrProperties[arrTemp[0]] = arrTemp[1];
        }

        //If available
        if(arrProperties['available'] != 0){
            //If price changed
            if(arrProperties['pricechanged']  != 0) {
                document.getElementById("subloadingmessagechanged").innerHTML = "<b>Let op!</b><br/>De door u gezochte aanbieding is niet meer beschikbaar. U heeft de mogelijkheid om uw verblijf te reserveren voor<br/>de n&uacute; getoonde prijs";
                document.getElementById("subloadingmessagechecking").style.color = "#CCCCCC";
                setTimeout("dtShowChangedPrice('"+arrProperties['price']+"','"+arrProperties['breakfastincluded']+"')",5000);
            } else {
                dtShowPriceDetails();
            }
        } else {
            document.getElementById("subloadingmessagechecking").innerHTML = "De door u gezochte aanbieding is voor deze periode helaas niet meer beschikbaar. Door op onderstaande link te klikken kunt terug gaan naar de hotelpagina en daar een andere datum kiezen. Of u kunt contact opnemen met ons servicecentre.<br/><div align='center'><a href='"+strDetailUrl+"'>[Terug naar hotelpagina]</a></div>";
        }
    }
}

function dtShowChangedPrice(intPrice,boolBreakfast) {
    document.getElementById("price").innerHTML = "&euro; "+intPrice;
    var strHTML = document.getElementById("condition").innerHTML;

    var strToReplace,strWithReplace;
    if (boolBreakfast == 1) {
        strToReplace = "excl";
        strWithReplace = "incl";
    } else {
        strToReplace = "incl";
        strWithReplace = "excl";
    }

    document.getElementById("condition").innerHTML = strHTML.replace(strToReplace,strWithReplace);
    dtShowPriceDetails();
}

function dtShowPriceDetails() {
    document.getElementById("loadingmessage").style.display = "none";
    document.getElementById("divdetail").style.display = "";
}

function getGaLinkerUrl(url, object) {

    if (object == undefined) {
        if (typeof _gaq != 'undefined' && typeof _gaq == 'object') {
            object = _gaq;
        } else {
            window.open(url, 'bookwindow', 'width=1010, height=700, location=no, status=yes, resizable=yes, menubar=no, directories=no, scrollbars=yes');
        }
    } else if (typeof object != undefined && typeof object == 'object') {

    }

    object.push(function() {

        var tracker = _gat._getTrackerByName("");
        var linkerUrl = tracker._getLinkerUrl(url);

        if (typeof tracker != undefined) {
            var linkerUrl = tracker._getLinkerUrl(url);
        } else {
            var linkerUrl = '&';
        }

        var b = linkerUrl.substr(url.length);
        var newUrl = url + escape(b);

        window.open(newUrl, 'bookwindow', 'width=1010,height=700,location=no,status=yes,resizable=yes,menubar=no,directories=no,scrollbars=yes');

    });

    return true;
}

function initializeMap(title, latitude, longitude) {
    var myLatlng = new google.maps.LatLng(latitude,longitude);

    var myOptions = {
        zoom: 11,
        minZoom: 2,
        panControl: true,
        zoomControl: true,
        scaleControl: false,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        scrollwheel: false
    }

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: title
    });

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map, marker);
    });
}
