function openWindow(img1, img2, img3, title1, title2, title3) {
    var images = new Array();
    var i = 0;
    if(img1) {
        images[i++] = [img1, title1];
    }
    if(img2) {
        images[i++] = [img2, title2];
    }
    if(img3) {
        images[i++] = [img3, title3];
    }
    jQuery.slimbox(images, 0);
    return false;
}


function getUrlVars(){
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value){
        vars[key] = value;
    });
    return vars;
}

var CurrLocation = window.location.pathname;
var getArr = getUrlVars();
// delay the execution
var execTimer;
var delay = 1000;

function delayExecution() {
	if(execTimer) {
        clearTimeout(execTimer);
    }
	execTimer = setTimeout(submitFilter, delay);
}

function submitFilter() {     
    
    var zoomLavel=map.getZoom();
    var mapCenter=map.getCenter();
    
	var filter = 'filter=';
    var location = 'index.php';
	$('input[type="checkbox"]').each(function(){
		if ($(this).is(':checked')) {
			filter += $(this).val() + ',';
		} 
	});
    if (getArr['cityID']) {
        if (getArr['cityID']) {
            location += '?cityID=' + getArr['cityID'] + '&';
            //if (getArr['billboardID']) {
            //    location += 'billboardID=' + getArr['billboardID'] + '&';
            //}
        }
        //else {
        //    location += '?billboardID=' + getArr['billboardID'] + '&';
        //}
    }
    else {
        location += '?';
    }
    location += filter;
    location += '&zoom='+zoomLavel;
    location += '&mapCenter='+mapCenter;
    window.location.replace(location);
}

function updateTimer() {
	startTime = new Date();
}

// Select all then copy to clipboard
function selectAll(obj) {
    var textVal = eval(obj);
    textVal.focus();
    textVal.select();
}

$(document).ready(function(){
    
    // menu over effect
    $('ul.main-menu li a.active').parent().addClass('over');
    $('ul.main-menu li').hover(function(){
        if ($(this).children('a.active').length == 0) {
            $(this).addClass('over');
        }
    }, function(){
        if ($(this).children('a.active').length == 0) {
            $(this).removeClass('over');
        }
    });
    
    // A hack for IE
    if ($.browser.msie) {
      $('input[type="checkbox"]').click(function() {
        this.blur();
        this.focus();
      });
    }

    // redirect
    $('input[type="checkbox"]').change(function(){
        delayExecution();
    });
    
    $('a[rel="lightbox"]').live('click', function(){
            $(this).lightbox();
    });
    
});
