$(document).ready(function() {
    $('#type').SelectCustomizer();
    $('#destination').SelectCustomizer();
    $('#departure').SelectCustomizer();
    $('#price').SelectCustomizer();

    $("#nav_tab > ul").tabs();

    $("#close_ecran").click(function(){
        $("#ecran").slideToggle("fast");
    });

    /* Using custom settings */
    /*$("#link_to_login").fancybox({
        'hideOnContentClick': false,
        'frameWidth': 300,
        'frameHeight': 200
    });
    $("#link_to_account").fancybox({
        'hideOnContentClick': false,
        'frameWidth': 300,
        'frameHeight': 350
    });*/
    $(".fancy_map").fancybox({
        'hideOnContentClick': false,
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	520,
        'speedOut'		:	320,
        'overlayShow'	:	false,
        'width': 520,
        'height': 320
    });

    // submit form login in ajax
    $("#submit_login").live("click", function() {
        var act = $("#form_login").attr("action");
        $.post(act, $("#form_login").serialize(), function(data){
            if (data == 'false')
            {
                $("#form_login > table > tbody").append('<tr><td colspan="2">The username and/or password is invalid.</td></tr>');
            }
            else
            {
                $.fn.fancybox.close();
            }
        });
    });
    /*
    // formulaire de contact
    $(".link_to_contact").fancybox({
        'hideOnContentClick': false,
        'frameWidth': 400,
        'frameHeight': 400
    });*/
    $("#voir_video > p > a").fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	480,
        'speedOut'		:	270,
        'overlayShow'	:	false,
        'width':            480,
        'hieght':            270
    });
// vitrine
//    setInterval("animateShowcase()", 5000);
   
});

function animateShowcase()
{
    if ($("#vitrine").length == 0)
        return false;
    var cover = rand (1, 13);
    $('.li_vitrine').each(function(i){
        var id = $(this).attr('id');
        if (cover == id.split('_')[2] &&  $("#"+id+'> .best').length == 0 )
            $(this).toggle("scale", {}, function(e){
                var new_cover = rand (1, 13);
                $("#"+id+'> .cover').html('<a href="#"><span/><img border="0" src="/images/brochures_small/cover-'+new_cover+'.jpg"/></a>');
                $(this).toggle();
            });
    });
}

function rand (min, max) {
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

// This file demonstrates the different options of the pagination plugin
// It also demonstrates how to use a JavaScript data structure to
// generate the paginated content and how to display more than one
// item per page with items_per_page.

/**
             * Callback function that displays the content.
             *
             * Gets called every time the user clicks on a pagination link.
             *
             * @param {int}page_index New Page index
             * @param {jQuery} jq the container with the pagination links as a jQuery object
             */
function pageselectCallback(page_index, jq){
    // Get number of elements per pagionation page from form
    var items_per_page = $('#items_per_page').val();
    var max_elem = Math.min((page_index+1) * items_per_page, members.length);
    var newcontent = '';

    // Iterate through a selection of the content and build an HTML string
    for(var i=page_index*items_per_page;i<max_elem;i++)
    {
        newcontent += '<dt>' + members[i][0] + '</dt>';
        newcontent += '<dd class="state">' + members[i][2] + '</dd>';
        newcontent += '<dd class="party">' + members[i][3] + '</dd>';
    }

    // Replace old content with new content
    $('#Searchresult').html(newcontent);

    // Prevent click eventpropagation
    return false;
}

  
// **************************************************************************
// Copyright 2007 - 2008 The JSLab Team, Tavs Dokkedahl and Allan Jacobs
// Contact: http://www.jslab.dk/contact.php
//
// This file is part of the JSLab Standard Library (JSL) Program.
//
// JSL is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// any later version.
//
// JSL is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// ***************************************************************************
// File created 2009-01-30 12:00:25

// Copy an array
Array.prototype.copy =
    function() {
        return [].concat(this);
    };

// Return elements which are in A but not in arg0 through argn
Array.prototype.diff =
    function() {
        var a1 = this;
        var a = a2 = null;
        var n = 0;
        while(n < arguments.length) {
            a = [];
            a2 = arguments[n];
            var l = a1.length;
            var l2 = a2.length;
            var diff = true;
            for(var i=0; i<l; i++) {
                for(var j=0; j<l2; j++) {
                    if (a1[i] === a2[j]) {
                        diff = false;
                        break;
                    }
                }
                diff ? a.push(a1[i]) : diff = true;
            }
            a1 = a;
            n++;
        }
        return a.unique();
    };

// Check whether n number of arrays are disjoint
Array.prototype.disjoint =
    function() {
        var args = [];
        var l = arguments.length;
        if (!l)
            return true;
        for(var i=0; i<l; i++)
            args.push(arguments[i]);
        return Array.prototype.intersect.apply(this,args).length > 0 ? false : true;
    };

// Compute the intersection of n arrays
Array.prototype.intersect =
    function() {
        if (!arguments.length)
            return [];
        var a1 = this;
        var a = a2 = null;
        var n = 0;
        while(n < arguments.length) {
            a = [];
            a2 = arguments[n];
            var l = a1.length;
            var l2 = a2.length;
            for(var i=0; i<l; i++) {
                for(var j=0; j<l2; j++) {
                    if (a1[i] === a2[j])
                        a.push(a1[i]);
                }
            }
            a1 = a;
            n++;
        }
        return a.unique();
    };

// Apply each member of the array as the first argument to the function f
Array.prototype.mapFunction =
    function(f) {
        var l = this.length;
        for(var i=0; i<l; i++)
            f(this[i]);
    };

// Apply the method m to each member of an array
Array.prototype.mapMethod =
    function(m) {
        var a = [];
        for(var i=1; i<arguments.length; i++)
            a.push(arguments[i]);
        var l = this.length;
        for(var i=0; i<l; i++)
            m.apply(this[i],a);
    };

// Pad an array to given size with a given value
Array.prototype.pad =
    function(s,v) {
        var l = Math.abs(s) - this.length;
        var a = [].concat(this);
        if (l <= 0)
            return a;
        for(var i=0; i<l; i++)
            s < 0 ? a.unshift(v) : a.push(v);
        return a;
    };

// Randomize elements in an array
Array.prototype.randomize =
    function(ru) {
        if (!ru)
            this.sort(function(){
                return ((Math.random() * 3) | 0) - 1;
            });
        else {
            var a = [].concat(this);
            var l = this.length;
            var al = n = 0;
            for(var i=0; i<l; i++) {
                al = a.length;
                // Get random integer in [0,a.length-1]
                n = Math.floor((Math.random() * al));
                // Copy random element from a to this
                this[i] = a[n];
                // If n was last element in a just pop a[n]
                if (n == al - 1)
                    a.pop();
                // Else copy last element from a to n and pop last element from a
                else {
                    a[n] = a[al - 1];
                    a.pop();
                }
            }
        }
    };

// Remove values from an array optionally using a custom function
Array.prototype.remove =
    function(f) {
        if (!f)
            f = function(i) {
                return i == undefined || i == null ? true : false;
            };
        var l = this.length;
        var n = 0;
        for(var i=0; i<l; i++)
            f(this[i]) ? n++ : this[i-n] = this[i];
        this.length = this.length - n;
    };

// Get the union of n arrays
Array.prototype.union =
    function() {
        var a = [].concat(this);
        var l = arguments.length;
        for(var i=0; i<l; i++) {
            a = a.concat(arguments[i]);
        }
        return a.unique();
    };

// Return new array with duplicate values removed
Array.prototype.unique =
    function() {
        var a = [];
        var l = this.length;
        for(var i=0; i<l; i++) {
            for(var j=i+1; j<l; j++) {
                // If this[i] is found later in the array
                if (this[i] === this[j])
                    j = ++i;
            }
            a.push(this[i]);
        }
        return a;
    };

function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array
    //
    // version: 911.718
    // discuss at: http://phpjs.org/functions/in_array
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }

    return false;
}



function array_intersect () {
    // Returns the entries of arr1 that have values which are present in all the other arguments
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/array_intersect
    // +   original by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: These only output associative arrays (would need to be
    // %        note 1: all numeric and counting from zero to be numeric)
    // *     example 1: $array1 = {'a' : 'green', 0:'red', 1: 'blue'};
    // *     example 1: $array2 = {'b' : 'green', 0:'yellow', 1:'red'};
    // *     example 1: $array3 = ['green', 'red'];
    // *     example 1: $result = array_intersect($array1, $array2, $array3);
    // *     returns 1: {0: 'red', a: 'green'}
    var arr1 = arguments[0], retArr = new Array();
    ;
    var k1 = '', arr = {}, i = 0, k = '';

        arr1keys:
        for (k1 in arr1) {
            arrs:
            for (i=1; i < arguments.length; i++) {
                arr = arguments[i];
                for (k in arr) {
                    if (arr[k] === arr1[k1]) {
                        if (i === arguments.length-1) {
                            retArr[k1] = arr1[k1];
                        }
                        // If the innermost loop always leads at least once to an equal value, continue the loop until done
                        continue arrs;
                    }
                }
                // If it reaches here, it wasn't found in at least one array, so try next value
                continue arr1keys;
            }
        }

    return retArr;
}
