function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

Lightview.options.backgroundColor = '#0c1d2f';

function openModal(content) {
    $('tmp').update(content);
    Lightview.show({
        href: 'tmp',
        rel: 'inline',
        options: {
            width: 400,
            height: 300,
            topclose: true
        }
    });
}

function openAbout(lang) {
    Lightview.show({
        href: 'about.php?lang='+lang,
        rel: 'ajax',
        options: {
            width: 800,
            height: 620,
            topclose: true
        }
    });
}

function openNews(id) {
    Lightview.show({
        href: 'news.php?id='+id,
        rel: 'ajax',
        options: {
            backgroundColor: '#eee',
            width: 500,
            height: 450,
            topclose: true
        }
    });
}

function openPortfolio(id, lang) {
    Lightview.show({
        href: 'portfolio.php?id='+id+'&lang='+lang,
        rel: 'iframe',
        options: {
            width: 800,
            height: 600,
            topclose: true
        }
    });
}

function openPress(id, lang) {
    Lightview.show({
        href: 'press.php?id='+id+'&lang='+lang,
        rel: 'iframe',
        options: {
            width: 800,
            height: 600,
            topclose: true
        }
    });
}

function openPicture(path) {
    Lightview.show({
        href: path,
        rel: 'image',
        options: {
            autosize: true,
            topclose: true
        }
    });
}

function openGallery() {
    Lightview.show({
        href: 'gallery.swf',
        rel: 'flash',
        options: {
            width: 800,
            height: 600,
            fullscreen: true,
            flashvars: 'xmlFile=gallery.php',
            topclose: true
        }
    });
}

function openContactForm(lang) {
    Lightview.show({
        href: 'contact.php?lang='+lang,
        rel: 'ajax',
        options: {
            width: 500,
            height: 450,
            topclose: true,
            ajax: {
                onComplete: function(){
                    $('contact-form').observe('submit', submitForm);
                }
            }
        }
    });
}

function submitForm(event) {
    Event.stop(event);
    
    var text = $('contact-form').down('input').value.strip();
    if (!text) return;
        
    Lightview.show({
        href: 'contact.php',
        rel: 'ajax',
        options: {
            title: 'results',
            menubar: false,
            topclose: true,
            autosize: true,
            ajax: {
                parameters: Form.serialize('contact-form')
            }
        }
    });
}

document.observe('lightview:hidden', function() {
    $('tmp').update('');
});
