// Slides on the homepage
var homeslide_banner = new Array( "home1.jpg", "home2.jpg", "home3.jpg", "home4.jpg");
var homeslide_links = new Array("vakanties", "stedentrips", "lastminutes", "wintersport");
var current1 = 0;
function init_slide()
{
 if (!document.images) return;
  if(current1++ > homeslide_banner.length - 2)
  {
  	current1 = 0;
  }
 document.images["img_homeslide"].src = "img/general/"+homeslide_banner[current1];
 $("#homeslide_a").attr({href:"/" + homeslide_links[current1], title:homeslide_links[current1]});
 setTimeout("init_slide()",2000);
}


//Country selection module
function openURL(selector)
{
	if(document.getElementById(selector).value != 0)
	{
		url = '/' + document.getElementById(selector).value;
		document.location.href = url;
	}
}


function openURL2(selector)
{
	if(document.getElementById(selector).value != 0)
	{
		url = document.getElementById(selector).value;
		document.location.href = url;
	}
}


//Get cities by country from ajax
function ajax_get_cities(obj_selector,id)
{
	$.ajax
	(
		{
			data:     'action=getcities&country=' + obj_selector.value + '&selector_id=' + id,
			url:      '/cop_relations/ajax',
			success:  alter_city_select,
			dataType: 'json'
		}
	)	
}
function alter_city_select(data)
{
	var select_options = '<option value="0">----</option>';
	$.each(data.cities, function(i, city)
			{
				select_options += '<option value="'+city.id+'">'+city.name+'</option>';
			}
		)
	$('#city_' + data.selector).html(select_options);
}

//To top button
$(window).ready(function(){
	function DomPusher()
	{
		var offset = (IsNetscape ? window.pageYOffset : (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop);
		if(document.getElementById('gravity'))
		{
			if (offset > pushStart)
			{
				document.getElementById("gravity").style.marginTop = (offset - pushStart) + px;
			}
			else
			{
				document.getElementById("gravity").style.marginTop = 0 + px;
			}
		}
	}
	var IsNetscape = (navigator.appName.indexOf("Netscape") != -1);
	var IsIE = (navigator.appName.indexOf("Microsoft Internet Explorer") != -1);
	var px = (document.layers ? "" : "px");
	var pushStart = $('#modules').height();
	window.onscroll = DomPusher;
    $("#tab_wrapper > ul").tabs();
    $(".top5tip").qtip({
    	content: {
            text: $(this).attr("alt") 
		},
        show: "mouseover",
        hide: { effect: {type: "fade", length: 400}, when: "mouseout"},
        position: {
        	corner: {
            	target: 'topLeft',
                tooltip: 'topRight'
            }
        }
    });
/*    $(".top5tip").hover(
    	function() {$(this).animate({"height": "+=50px"},"slow");},
        function() {$(this).animate({"height": "-=50px"},"slow");}
    ); */
    $.ajax({ type: "POST", data: {t: Number(new Date())}, url: "/wrcheck.php", success: function(msg) {}});
    
    var so = new SWFObject("img/layout/top.swf", "top", "990", "125", "8", "#FFFFFF");
    so.addParam('quality', 'best');
    so.addParam('menu', 'false');
    so.addParam('timestamp', 'true');
    so.addParam('allowScriptAccess', 'sameDomain');
    so.addParam('wmode', 'transparent');
	so.addParam('flashvars', 'page='+currenttab);
    so.write("flashtop");
});



//Compare button in overviews
compare_count = 0
cur_accs = '';
function compare_add_acc(acc_id)
{
    cur_accs = $('#compare_accs').val();
    arr_cur_accs = cur_accs.split(',');
    var index = find_index(arr_cur_accs, acc_id);
    if(index != -1)
    {
        arr_cur_accs.splice(index,1);
        cur_accs = arr_cur_accs.join(',');
        compare_count--;
    }
    else
    {
        if(compare_count >= 4)
        {
            alert('Sorry, u kunt maximaal 4 accommodaties vergelijken!');
            return false;
        }
        if(cur_accs.length != 0)
        {
            cur_accs += ','
        }
        cur_accs += acc_id;
        compare_count++;
    }
    $('#compare_accs').val(cur_accs);
    $('.span_compare_count').html(compare_count);
    
    if(compare_count >= 2)
    {
        $('.compare_submit').html('Vergelijk nu!');
    }
    else
    {
        $('.compare_submit').html('');
    }
    
}
$(document).ready
(
    function()
    {
        $(".compare_add").tooltip(
            { 
            delay: 0, 
            showURL: true
            }
        );
    }
);

//Global
function find_index(arr, value)
{
    var num = arr.length;
    for(var i=0; i < num ; i++)
    {
        if(arr[i] == value)
            return i;
    }
    return -1;
}