﻿$(document).ready(function() {
	$(".datePick").datepicker(		{showAnim: '',dateFormat: 'dd/mm/yy'}	); 
	$(".datePick2").datepicker(		{showAnim: '',dateFormat: 'dd/mm/yy'}	);
	$(".dateInput").datepicker(		{showAnim: '',dateFormat: 'dd/mm/yy'}	);
	$(".dateInputAcc").datepicker(		{showAnim: '',dateFormat: 'dd/mm/yy'}	);
    if ($(".date input").length > 0) {
        $(".date input").datepicker({
            showAnim: '',
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true,
            minDate: +0
        });
    }
    if ($(".dateAcc input").length > 0) {
        $(".dateAcc input").datepicker({
            showAnim: '',
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true,
            minDate: +0
        });
    }
    if ($(".dob input").length > 0) {
        $(".dob input").datepicker({
            showAnim: '',
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true,
            yearRange: '-80:-19'
        });
    }
    if ($(".dobChild input").length > 0) {
        $(".dobChild input").datepicker({
            showAnim: '',
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true,
            yearRange: '-20:+1'
        });
    }

    /* hotel photos */
    if ($(".hotelPhotos a").length > 0) {
        $("a[rel='hotel-photos']").colorbox({ transition: "fade" });
    }

    $(".toggleBtn").click(
		function() {
		    $(this).toggleClass('open').parent().find(".resortsList").slideToggle();
		    $(this).parent().toggleClass('open');
		    if ($(this).parent().hasClass('open') && !$(this).parent().find('ul').hasClass('nicescroll')) {
		        $(this).parent().find('ul').jScrollPane();
		        $(this).parent().find('ul').addClass('nicescroll');
		    }
		    return false;
		}
	)

    $(".expandList").click(
		function() {
		    $(this).toggleClass('open').parent().find(".resortsList").slideToggle();
		    $(this).parent().toggleClass('open');
		    if ($(this).parent().hasClass('open') && !$(this).parent().find('ul').hasClass('nicescroll')) {
		        $(this).parent().find('ul').jScrollPane();
		        $(this).parent().find('ul').addClass('nicescroll');
		    }
		    return false;
		}
	)

    jQuery.fn.ShowCountry = function() {

        $(this).toggleClass('open').parent().find(".resortsList").slideToggle();
        $(this).parent().toggleClass('open');
        if ($(this).parent().hasClass('open') && !$(this).parent().find('ul').hasClass('nicescroll')) {
            $(this).parent().find('ul').jScrollPane();
            $(this).parent().find('ul').addClass('nicescroll');
        }
    };

    /* shop page - bulets */
    $(function() {
        var bulletContainer = $('div.shopsListDescription');
        bulletContainer.hide().filter(':first').show();

        $('ul.shopsListHead a').click(function() {
            $("#hidShopIdWrapper > input").val($(this).attr("href"));
            localBulletContainer = $(this).parent().parent().parent().find("div.shopsListDescription");
            localBulletContainer.hide();
            localBulletContainer.filter(this.hash).show();

            $(this).parent().parent().find('li').removeClass('active');
            $(this).parent().addClass('active');

            return false;
        }).filter(':first').click();
    });

    /* fancy scrollbar */
    /* colorbox for Terms Show */
    if ($("#terms").length > 0) {
        $("#terms").colorbox({ width: "75%", inline: true, href: "#inline_example1" });
    }

    if ($("a.detailsClass").length > 0) {
        $("a.detailsClass").colorbox({ width: "75%", height: "75%" });
    }

    if ($("a.detailsClassGmap").length > 0) {
        $("a.detailsClassGmap").colorbox({ width: "500px", height: "500px", iframe: true });
    }

    if ($("a.detailsClassAccomPic").length > 0) {
        $("a.detailsClassAccomPic").colorbox();
    }

    if ($("a.ticketFullDetails").length > 0) {
        $("a.ticketFullDetails").colorbox({ width: "60%", height: "60%", iframe: true });
    }

    /* match products behavior */

    $(".seeDetailedInfo").click(function() {
        $(this).parent().parent().parent().parent().parent().parent().toggleClass("expandedBBox")
    })

    $(".collapseLink").click(function() {
        $(this).parent().parent().parent().parent().parent().parent().toggleClass("expandedBBox")
    })

    /* map script */

    var mapContainer = $('div.map');
    mapContainer.hide().filter(':first').show();
    $('.worldMapElements a').click(function() {

        id = $(this).attr("href").split("#");
        id = id[1];
        $("#" + id).show();
        $(".worldMap").hide();
        return false;
    });
    $("a#mapBack").click(function() {
        $(".map").hide();
        $(".worldMap").show();
        return false;
    });
    if ($(".tip a").length > 0) {
        $(".tip a[title]").qtip({
            position: {
                corner: {
                    target: 'topMiddle',
                    tooltip: 'bottomLeft'
                }
            }
        });
    }

});

function LoginAgent() {
    var user = document.getElementById('user').value;
    var passw = document.getElementById('passw').value;
    url = "AgentLoginHandler.ashx?action=login&user=" + user + "&password=" + passw;
    $.post(url, {},
                function(response) {
                    debugger;
                    if (response > 0) {
                        document.getElementById("AgentLoginForm").style.display = 'none';
                        document.getElementById("AgentLoggedIn").style.display = 'block';
                        document.getElementById("labelAgent").innerHTML = user;
                    }
                    else { document.getElementById('mess').innerHTML = "Invalid Agent"; }
                });
}

function Logout() {
    url = "AgentLoginHandler.ashx?action=logout";
    $.post(url, {},
                function(response) {
                    document.getElementById("AgentLoginForm").style.display = 'block';
                    document.getElementById('AgentLoggedIn').style.display = 'none';
                });
}

//(function ($) {

//    $(".ui-autocomplete-input").live("autocompleteopen", function () {
//        var autocomplete = $(this).data("autocomplete"),
//menu = autocomplete.menu;

//        if (!autocomplete.options.selectFirst) {
//            return;
//        }

//        menu.activate($.Event({ type: "mouseenter" }), menu.element.children().first());
//    });

//} (jQuery));

//(function ($) {

//    $.ui.autocomplete.prototype.options.autoSelect = true;
//    $(".ui-autocomplete-input").live("blur", function (event) {
//        var autocomplete = $(this).data("autocomplete");
//        if (!autocomplete.options.autoSelect || autocomplete.selectedItem) { return; }

//        var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i");
//        autocomplete.widget().children(".ui-menu-item").each(function () {
//            var item = $(this).data("item.autocomplete");
//            if (matcher.test(item.label || item.value || item)) {
//                autocomplete.selectedItem = item;
//                return false;
//            }
//        });
//        if (autocomplete.selectedItem) {
//            autocomplete._trigger("select", event, { item: autocomplete.selectedItem });
//        }
//    });

//} (jQuery));

//$(function(){
//    $('#gallery li').each(function(idx) {
//        $(this).data('index', (++idx));
//    });

//    $('#gallery').jcarousel({
//        scroll: 5,
//        initCallback: initCallbackFunction
//    })
//    
//    function initCallbackFunction(carousel) {
//        $('#img').bind('image-loaded',function() {
//            var idx =  $('#gallery li.active').data('index') - 2;
//            
//            carousel.scroll(idx);
//            return false;
//        });
//        
//    };

//    // load and fade-in thumbnails
//    $('#gallery li img').css('opacity', 0).each(function() {    
//        if (this.complete || this.readyState == 'complete') { $(this).animate({'opacity': 1}, 300) } 
//        else { $(this).load(function() { $(this).animate({'opacity': 1}, 300) }); }
//    });

//    $('#gallery').galleria({
//        // #img is the empty div which holds full size images
//        insert: '#img',
//        
//        // enable history plugin (shows last image displayed and set image path in URL)
//        history: false,
//        
//        // function fired when the image is displayed
//        onImage: function(image, caption, thumb) {        
//            // fade in the image 
//            image.hide().fadeIn(500);
//            
//            // animate active thumbnail's opacity to 1, other list elements to 0.6
//            thumb.parent().fadeTo(200, 1).siblings().fadeTo(200, 0.6)
//			
//			/* additional arrow for active class */
//			$('<span class="arr">&nbsp;</span').appendTo('.active');
//			
//			//console.log(thumb.parent());
//            
//            // $('#img').data('currentIndex', $li.data('index')).trigger('image-loaded')
//            
//            $('#img')
//                .trigger('image-loaded')
//                .hover(
//                    function(){ $('#img .caption').stop().animate({height: 40}, 250) },
//                    function(){ 
//                        if (!$('#show-caption').is(':checked')) {
//                            $('#img .caption').stop().animate({height: 0}, 250) 
//                        }
//                    }
//                );
//        },
//        
//        // function similar to onImage, but fired when thumbnail is displayed
//        onThumb: function(thumb) {
//            var $li = thumb.parent(),
//                opacity = $li.is('.active') ? 1 : 0.6;
//            
//            // hover effects for list elements
//            $li.hover(
//                function() { $li.fadeTo(200, 1); },
//                function() { $li.not('.active').fadeTo(200, opacity); }
//            )
//        }        
//    }).find('li:first').addClass('active') // display first image when Galleria is loaded
//    
//});
