var carouselInitialized_A = false;
var imgCurrentIndex_A = 1;
var carouselIndex_A = 1;
var photoTotalItems_A = 0;

function initCarousel_A() {
    if (carouselInitialized_A == false) {
        jQuery('#mycarousel').jcarousel({
            scroll: 1,
            initCallback: mycarousel_initCallback_A
        });
        carouselInitialized_A = true;
    }    
}

function mycarousel_initCallback_A(carousel, state) {
    photoTotalItems_A = $('#mycarousel li').length;
    showBigimg();

    jQuery('#mycarousel-next').bind('click', function () {
        nextPhoto_A(carousel);
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function () {
        prevPhoto_A(carousel);
        return false;
    });

    jQuery('#mycarousel-next-bottom').bind('click', function () {
        nextPhoto_A(carousel);
        return false;
    });

    jQuery('#mycarousel-prev-bottom').bind('click', function () {
        prevPhoto_A(carousel);
        return false;
    });

    jQuery('#mycarousel-next2').bind('click', function () {
        nextCarousel_A(carousel);
        return false;
    });

    jQuery('#mycarousel-prev2').bind('click', function () {
        prevCarousel_A(carousel);
        return false;
    });

    jQuery('.jcarousel-item').bind('click', function () {
        var imgIdx = jQuery(this).attr("jcarouselindex");
        showPhoto_A(imgIdx, carousel);
        return false;
    });
    
}

function prevCarousel_A(carousel) {
    carouselIndex_A--;
    if (carouselIndex_A == 0) {
        carousel.scroll(photoTotalItems_A);
        carouselIndex_A = photoTotalItems_A - 2;
    }
    else {
        carousel.prev();
    }
}

function nextCarousel_A(carousel) {
    carouselIndex_A++;
    if (carouselIndex_A > (photoTotalItems_A - 2)) {
        carousel.scroll(1);
        carouselIndex_A = 1;
    }
    else {
        carousel.next();
    }
}

function prevPhoto_A(carousel) {
    if (imgCurrentIndex_A > 1) {
        carousel.prev();
        carouselIndex_A--;
    }
    showPhoto_A((parseInt(imgCurrentIndex_A) - 1), carousel);
}

function nextPhoto_A(carousel) {
    showPhoto_A((parseInt(imgCurrentIndex_A) + 1), carousel);
}

function showPhoto_A(index, carousel) {
    if (index >= 1 && index <= photoTotalItems_A) {
        if (index >= imgCurrentIndex_A) {
            carousel.next();
            carouselIndex_A++;

        }
        else if (index < imgCurrentIndex_A) {
            //Do Not Scroll back         
            //if(index < (photoTotalItems - 3))
            //{
            //    carousel.prev();
            //    carouselIndex--;            
            //}
        }
        else {
            carouselIndex_A = index;
            carousel.scroll(index);

        }
        if (carouselIndex_A > (photoTotalItems_A - 2)) {
            carouselIndex_A = photoTotalItems_A - 2;
        }
    }
    else if (index == 0) {
        index = photoTotalItems_A;
        carouselIndex_A = photoTotalItems_A - 2;
        carousel.scroll(photoTotalItems_A);
    }
    else {
        index = 1;
        carouselIndex_A = 1;
        carousel.scroll(index);
    }
    imgCurrentIndex_A = index;
    showBigimg();
    //setNextPrevButtonState();
}

function setNextPrevButtonState_A() {
    if (imgCurrentIndex > 1) {
        $('.jcarousel-prev').removeClass('jcarousel-prev-disabled');
        $('.jcarousel-prev').removeClass('jcarousel-prev-disabled-horizontal');
    }
    else {
        $('.jcarousel-prev').addClass('jcarousel-prev-disabled');
        $('.jcarousel-prev').addClass('jcarousel-prev-disabled-horizontal');
    }
    if (imgCurrentIndex >= photoTotalItems) {
        $('.jcarousel-next').addClass('jcarousel-next-disabled');
        $('.jcarousel-next').addClass('jcarousel-next-disabled-horizontal');
    }
    else {
        $('.jcarousel-next').removeClass('jcarousel-next-disabled');
        $('.jcarousel-next').removeClass('jcarousel-next-disabled-horizontal');
    }
}


// manages tabs on accommodation page
function Tab(tabName)
{
    //Tabselection
    var chosen = document.getElementById("ctl00_cphBody_hChosen");
    var tab = document.getElementById("ctl00_cphBody_hTab");

    //Info items and titles
    var TabAccoInfo        = document.getElementById("TabAccoInfo");
    var TabAccoInfoMenu    = document.getElementById("TabAccoInfoMenu");
    var TabDestination     = document.getElementById("TabDestination");
    var TabDestinationMenu = document.getElementById("TabDestinationMenu");
    var TabPhotos          = document.getElementById("TabPhotos");
    var TabPhotosMenu      = document.getElementById("TabPhotosMenu"); 
    var TabWeather         = document.getElementById("TabWeather");
    var TabWeatherMenu     = document.getElementById("TabWeatherMenu");
    var TabOpinions        = document.getElementById("TabOpinions");
    var TabOpinionsMenu    = document.getElementById("TabOpinionsMenu");
    var TabPrices          = document.getElementById("TabPrices");
    var TabPricesMenu      = document.getElementById("TabPricesMenu");

    TabAccoInfo.className = "sntNoShow";
    TabAccoInfoMenu.className = "";
    TabDestination.className = "sntNoShow";
    TabDestinationMenu.className = "";
    TabPhotos.className = "sntNoShow";
    TabPhotosMenu.className = "";
    TabWeather.className = "sntNoShow";
    TabWeatherMenu.className = "";
    TabOpinions.className = "sntNoShow";
    TabOpinionsMenu.className = "";
    TabPrices.className = "sntNoShow";
    TabPricesMenu.className = "";

    var tabPos = 0;

    switch(tabName)
    {
        case "TabAccoInfo":
            TabAccoInfo.className = "sntShow";
            TabAccoInfoMenu.className = "active";
            tabPos = 0;
            break;
        case "TabDestination":
            TabDestination.className = "sntShow";
            TabDestinationMenu.className = "active";
            tabPos = 1;
            break;
        case "TabPhotos":
            TabPhotos.className = "sntShow";
            TabPhotosMenu.className = "active";
            initCarousel_A();
            tabPos = 2;
            break;
        case "TabWeather":
            TabWeather.className = "sntShow";
            TabWeatherMenu.className = "active";
            tabPos = 3;
            break;
        case "TabOpinions":
            TabOpinions.className = "sntShow";
            TabOpinionsMenu.className = "active";
            tabPos = 4;
            break;
        case "TabPrices":
            TabPrices.className = "sntShow";
            TabPricesMenu.className = "active";
            tabPos = 5;
            break;
        default:
            return;
    }
    
    chosen.value = tabName;
    tab.value = tabPos;
}

function SelectPrice(accoID, price, date, dur, unit, board, touropID, depart, linkID)
{
    //part for changing colors of selected link		
    if(linkID != 'Price_Min')
    {
	    var link                         = document.getElementById(linkID);
	    if(link == null) return false;
	    if (link.className == "niet-beschikbaar") return;
    			
	    var HiddenOldLinkStyleClassName  = document.getElementById("OldLinkStyleClassName");
        var HiddenOldLinkId              = document.getElementById("OldLinkId");               
        var ClickedPriceLink             = document.getElementById("ClickedPriceLink");	
        ClickedPriceLink.value           = linkID;
        
        if (HiddenOldLinkId.value != '')
        {
            var oldLink         = document.getElementById(HiddenOldLinkId.value);
            oldLink.className   = HiddenOldLinkStyleClassName.value;                
        }        
        
        HiddenOldLinkStyleClassName.value   = link.className;       
        HiddenOldLinkId.value               = linkID;         
        link.className                      = "selected";
        //end
    }
    
	document.getElementById('priceRemark').style.display = 'none';
	document.getElementById('prijsoverzicht').style.display = '';
	document.getElementById('wait').style.display = '';
	document.getElementById('prices_list').style.display = 'none';
	document.getElementById('btnBook').style.display      = 'none';
	document.getElementById('btnPriceGaruantuee').style.display      = 'none';
		
	var url = Master_BasePath + "GetReceipt.aspx";
	url    += "?acco=" + accoID;
	url    += "&price=" + price;
	url    += "&date=" + date;
	url    += "&dur=" + dur;
	url    += "&unit=" + unit;
	url    += "&board=" + board;
	url    += "&tourop=" + touropID;
	url    += "&depart=" + depart;
	url += "&linkid=" + linkID;	
	
	var req = new Request();
	req.GetNoCache(url, SelectPriceResult);
	
	//location.href = "#PriceDetailsAnchor";
//	alert(url);
//    alert("accoID:"+accoID+" price:"+price+" date:"+date+" dur:"+dur+" unit:"+unit+" board:"+board+" touropID:"+touropID+" depart:"+depart+" linkID:"+linkID);
}

function SelectPriceResult(result) 
{
	if (result.readyState != ReadyState.Complete) return;
	if (result.status == HttpStatus.OK && result.responseText != "") 
	{
		eval(result.responseText);
//		alert(result.responseText );
	}
	else
	{
		alert("error\n" +  result.responseText );
	}
}

function Book(to, pc, tr, dt, du, dp, ut, bo)
{
	var url = Master_BasePath + "Boeken/Start.aspx";
	url    += "?Action=book&fill=true";
	url    += "&to=" + to;
	url    += "&pc=" + pc;
	url    += "&tr=" + tr;
	url    += "&dt=" + dt;
	url    += "&du=" + du;
	url    += "&dp=" + dp;
	url    += "&ut=" + ut;
	url    += "&bo=" + bo;
	
	location.href = url;
}

function AddAccoToSavedAccos(type, accoID) 
{
	var url = Master_BasePath + "AccoCookies.aspx?Action=Save&Type=" + type + "&AccoID="+accoID;
	var req = new Request();
	req.GetNoCache(url, AddAccoToSavedAccosResult);
}

function AddAccoToSavedAccosResult(result) 
{
	if (result.readyState != ReadyState.Complete) return;
	if (result.status == HttpStatus.OK && result.responseText != "") {
		if (result.responseText == "ERROR")
		{
		    alert("Error");
		}
		else
		{
		    //alert("Acco saved");
		    ResetSavedVisitedNumber()
		}
	}
}

function ShowRoomDescription(roomId)
{
    var roomOverlay = document.getElementById("roomDescOverlayMain");
    var popupOverlay = document.getElementById(roomId);
    var overlayContent = document.getElementById("roomDescOverlay");
    if ((popupOverlay == null) || (popupOverlay == null) || (overlayContent == null)) return;
    
    CenterRoomElement();
    overlayContent.innerHTML = popupOverlay.innerHTML;
    roomOverlay.style.visibility = "visible";
}

function HideRoomDescription(roomId)
{
    var roomOverlay = document.getElementById("roomDescOverlayMain");
    var overlayContent = document.getElementById("roomDescOverlay");
    if (roomOverlay == null) return;
    
    if (overlayContent != null)
        overlayContent.innerHTML = "";
    roomOverlay.style.visibility = "hidden";
}

function CenterRoomElement() {
    var pop = document.getElementById("roomDescOverlay");
    if(pop == null) return;
    
    var posy = 0;
    var winy = 0;
    var winscroll = 0;
    var poph = pop.offsetHeight;
    
    if(window.pageYOffset){
        winscroll = window.pageYOffset;
        winy = window.innerHeight;
    }else{
        winscroll = iecompattest().scrollTop;
        winy = iecompattest().clientHeight;
    }
    
    if(poph >= winy) {
        posy = winscroll;
    } else {
        posy = ((winy - poph) / 2) + winscroll;
    }

    pop.style.top = posy + "px";
    //pop.style.top = '400px';
}

function DisablePrice()
{
	var ClickedLinkHiddenField = document.getElementById("ClickedPriceLink");
	if (ClickedLinkHiddenField != null && ClickedLinkHiddenField.value != '')
	{
		var link = document.getElementById(ClickedLinkHiddenField.value);
		if(link != null)
		{		        
			link.className = "niet-beschikbaar";
			link.onClick = "return false";
            
			var HiddenOldLinkId = document.getElementById("OldLinkId");
			if(HiddenOldLinkId != null)
			{		        
				HiddenOldLinkId.value = "";
			} 
            
			return false;
		}           
    }       	
}
