var root = 'http://www.kosler-hairlounge.de/';
var last;
var images = new Array();

window.addEvent('load', function() {ajax_update();});

function Accord(first) {
  $$('a.titlelink').each(function(x) {
    x.replaceWith(x.getFirst());
  });
  var newsh = $$('.news_off');
	newsh.each(function(nw){
    nw.setProperty('class','news');
  });
  var accordion = new Accordion(
    'span.news_head', 
    'div.news_content', 
    {
	     opacity: false,
	     height: false, /**/
	     onBackground: function(toggler, element){
		      toggler.setProperty('class', 'news_head_off');
		      toggler.setStyle('cursor','pointer');
		      toggler.getParent().setStyle('padding','0px');
		      element.setStyle('display','none'); /**/
	        },
	     onActive: function(toggler, element){
		      toggler.setProperty('class','news_head');
		      toggler.setStyle('cursor','default');
		      toggler.getParent().setStyle('padding','5px 0 15px 0');
		      element.setStyle('display','block'); /**/
	        }
    }, 
    $('wrap')
  );
};

function Thumbs(full, tmbs, folder, team) { 
  last = $($(full).getFirst().getProperty('class'));
  $$('#'+tmbs+' a').each(function(link){
    link.getFirst().setStyle('cursor','pointer');
    link.replaceWith(link.getFirst());
  });
  last.setStyle('opacity',0.4);
  $$('#'+tmbs+' img').each(function(tmb){
      tmb.addEvent('click',function() {
        if(tmb != last) {
          $('loadbox').setProperty('class','on');
          new Asset.images([root+'img/'+folder+'/'+tmb.getProperty('id')+'.jpg'], {
              onComplete:  function() {
                $('loadbox').setProperty('class','off');
                $(full).getFirst().setProperty('src',root+'img/'+folder+'/'+tmb.getProperty('id')+'.jpg');
                }
              });
          tmb.setStyle('opacity',0.4);
          last.setStyle('opacity',1);
          last = tmb;
        }
        if(team) {
          new Ajax(
              root+"req_team.php?id=" + tmb.getProperty('id').split("t")[1], 
              {
                method: 'get',
                update: 'team_about'
              }
            ).request();
        }
      });
  });
};

function newW() {
  $$('a.newW').setProperty('target','_blank');
}

function ajax_update() {
  newW();
  /* var flash_bg = '<object type="application/x-shockwave-flash">
    <param name="movie" value="' + root + 'bg.swf" />
    <param value="transparent" name="wmode" />
    <param name="width" value="100%" />
    <param name="height" value="100%" />
    <param name="zindex" value="1" />
    <embed  width="100%" height="100%" menu="false" zindex="1" ' + 
      'type="application/x-shockwave-flash" src="' + root + 'bg.swf" ' +
      'pluginspage="http://www.adobe.com/go/getflashplayer" ' + 
      'wmode="transparent" />
  </object>' */
  //$('outer').setHTML(flash_bg);
  req_el = new Element('div',{'id':'req'});
  req_el.injectInside($E('body'));
  $$('#navigation a').each(function(mnu) {
    mnu.setProperty('href','#');
    mnu.setProperty('onclick','return false');
    mnu.addEvent('click',function(){
      last = "";
      mnu.blur();
      $$('.nav_active').setProperty('class','nav_link');
      mnu.getParent().setProperty('class','nav_active');
      $('loadbox').setProperty('class','on');
      if (mnu.getProperty('id').split("_")[1] == "kollektion" || mnu.getProperty('id').split("_")[1] == "media") {
                  try 
                  {
                    $('content').setStyle('width','780px');
                  }
                  catch(err) {}
                }
      new Ajax(
        root+"inc_"+mnu.getProperty('id').split('_')[1]+".php?js=true", 
        {
          method: 'get',
          update: 'wrap',
          evalScripts:  false,
          onComplete: function() { 
            switch(mnu.getProperty('id').split("_")[1]) {
                  case 'news':
                    Accord();
                    break;
                  case 'team':
                    Thumbs('team_fullview','thumbnails','team',true);
                    break;
                  case 'kollektion':
                    Thumbs('fullview','thumbnails','kollektion/2011');
                    break;
                  case 'hairlounge':
                    Thumbs('kollektion_fullview','kollektion_tmbs','hairlounge');
                    break;
                }
            newW();
            $('loadbox').setProperty('class','off');
            if (mnu.getProperty('id').split("_")[1] != "kollektion" && mnu.getProperty('id').split("_")[1] != "media" ) {
              if($('content').getStyle('width').toInt() > 580) 
                //$('wide_content').setProperty('id','content');
                new Fx.Style($('content'), 'width', {duration: 200, fps:50}).start(580);   
            }
          }
          
        }
      ).request();
    });
  });
};
