// JavaScript Document
$(document).ready(function(){	
	//first load
	$.ajax({
    	type:"POST",
    	url:"filtervouchers.php",
   	 	data:"type=&vehicle=&avail=",
   	 	success:function(data){

            $('.results').html(data);
    	}
	});//end ajax

	$('div.filters').delegate('input:checkbox', 'change', function() {
       var type = $('input.exp_type:checked').map(function ()
       {
           return $(this).attr('value');
       }).get().join(',');
	   var vehicle = $('input.vehicle_type:checked').map(function ()
       {
           return $(this).attr('value');
       }).get().join(',');
	   var avail = $('input.availability:checked').map(function ()
       {
           return $(this).attr('value');
       }).get().join(',');
	   var price = $('input.price:checked').map(function ()
       {
           return $(this).attr('value');
       }).get().join(',');

       $.ajax({
            type:"POST",
            url:"filtervouchers.php",
            data:"type="+type+"&vehicle="+vehicle+"&avail="+avail+"&price="+price,
            success:function(data){
                    $('.results').html(data);
            }
        });//end ajax
   })
   
   $('a.poplight[href^=#]').live('click', function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close">Close</a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on 		fading transparencies 
    return false;
	});

	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    	$('#fade , .popup_block').fadeOut(function() {
        	$('#fade, a.close').remove(); //fade them both out
    	});
    	return false;
	});
	
	$(".toggle_container").hide();

	$("h4.trigger").toggle(function(){
		$(this).addClass("show"); 
		}, function () {
		$(this).removeClass("show");
	});
	
	$("h4.trigger").click(function(){
		$(this).next(".toggle_container").slideToggle("slow,");
	});
});

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
