$(function(){
    
    $('.fpcontent').click(function() {
        var mypos = $(this).getcv('position');
        if (mypos == 1 && $(this).getcv('catid') == 0) return false;
        if (mypos == 1) {
            // Already in front
            document.location = '/sys/overview/?category='+$(this).getcv('catid');
        } else {
            // Get targets
            var front = $('.location1');
            var back = $('.location'+mypos);
            
            // Animate me to front
            $(this).stop(true, true).animate({zIndex: parseInt(front.css('z-index'))+1, left: front.position().left, top: front.position().top}, 250,'', function() {
                $(this).find('.maintxt').fadeIn(1000);
                if ($(this).getcv('catid') == 0) $('#qformcontainer').fadeIn(1000);
            });
            // Animate front to me
            $('.position1').stop(true, true).animate({zIndex: parseInt(back.css('z-index'))+1, left: back.position().left, top: back.position().top}, 250).find('.maintxt').hide();
            if ($('.position1').getcv('catid') == 0) $('#qformcontainer').hide();
            // Change positions
            $('.position1').setcv('position', mypos);
            $(this).setcv('position', 1);
            // Show/Hide quickform
            
        }
        return false;
    }).css('cursor', 'pointer');
    
    $('#resellerdialog').stddialog({
        'Log in' : function() {
            $('#resellerloginform').submit();
        }
    })
    
    $('#resellerlogin').click(function() {
        $('#resellerdialog').dialog('open');
    })
    
    loadQform({});
    
    $('.maintxt').hide();
});

function loadQform(opts) {
    $.post('qload.php', opts, function(data) {
        $('#qformcontainer').html(data);
        $('select[name="tourcat"]').change(function() {
            loadQform({tourcat: $(this).find('option:selected').val()});
        })
        $('select[name="tourid"]').change(function() {
            document.location = '/sys/details/?category='+$('select[name="tourcat"] option:selected').val()+'&tourid='+$(this).find('option:selected').val();
        })
    })
}

