var actPage = 'home';
var actLang = 'de';
var actParams = '';

function choseLang( lang ) {
  $.cookie('language', lang, { expires: 30, path: '/' });
  actLang = lang;
  showContent(actPage);
}

function showContent(content,params) {
    actPage = content;
    $.cookie('actPage', content, { expires: 7, path: '/' });
    actLang = ($.cookie('language')) ? $.cookie('language') : actLang;
    $('div.menuItem a').removeClass('active');
    $('div.menuItem a#'+content).addClass('active');
	
	
    if(content == "news") {
      showContent('home');
      var newsForm = 'news_'+actLang+'.php';
      $('#content').prepend(' <div id="dia" style="padding:0px;display:none;overflow:hidden;"></div>');
      var iframe  = '<iframe id="new" src="'+newsForm+'" scrolling="no" style="padding:0px;overflow:hidden;width:500px;height:500px;" frameborder="0" allowtransparency="true"></iframe><br>';

      //$('#dia').dialog('destroy');
      //$('#dia').empty();

      $('#dia').append(iframe);

      $('#dia').dialog({
        title: 'newsletter',
        resizable: false,
        modal: true,
        width: 500,
        height: 520,
        overlay: {
            opacity: 0.5,
            background: "black"
        }
      });

      $('#dia').dialog('open');
      /*
      $('.ui-dialog-titlebar-close').click(function() {
        $('#dia').dialog("close");
      });
      */

    }
    else {
      $('#contentItem').hide();
      $('#contentItem').empty();
      if(content == 'home') {
        var url = 'handle.php?task=news';
      }
      else {
        var url = content+'_'+actLang+'.php';
        
      }
      if(content == 'gallery') {
        if(!params){
          params = actParams;
        }
      }
      if(params) {
        url += '?'+params;
        actParams = params;
      }
      
      var html = $.ajax({
        url: url,
        async: false
       }).responseText;
      //alert(html);
      //console.log(html);
      $("#contentItem").append(html);
      $('#contentItem').fadeIn('slow');
    }
    /*
    if(content == 'music') {
      window.setTimeout(function() {
      var so = new SWFObject("flashmp3player.swf", "player", "250", "180", "9");
      so.addParam("quality", "high");
      so.addVariable("content_path","../moojahMusic"); // Location of a folder with mp3 files (relative to php script).
      so.addVariable("color_path","default.xml"); // Location of xml file with color settings.
      so.addVariable("script_path","flashmp3player.php"); // Location of php script.
      so.write("player");
      },2000);
    }
    */
}


$(document).ready(function() {

  if( $.cookie('actPage') ) {
    actPage = ($.cookie('actPage')) ? $.cookie('actPage') : actPage;
  }

  // logo click => home
  $('#logo').click(function(e) {
    showContent('home');
    return false;
  });

  // menu click
  $('div.menuItem a').click(function(e) {
    // get id
    var id = $(e.target).attr('id');
    showContent(id);
    return false;
  });

  showContent(actPage);

});


