var $j = jQuery.noConflict();
//var item = {};
var isForm = 0;
var isRss = 0;
var isGb = 0;
var isLang = 0;
var isIE = 0;

$j(document).ready(pageLoaderInit);
function pageLoaderInit(){
	$j("a[class='concert_rss']").click(function(rssEvent){
		isRss = 1;
			location.href = this;
	});
		//für Gallery
	$j("a[class='thickbox']").click(function(galEvent){
		galEvent.preventDefault();
		tb_show(this.title,""+this,this.rel);
	});

	$j("a[class='extern']").click(function(e){
	location.href = this;
	});
  $j("a").click(function(event){
  	if(this.href.indexOf('http://')==0 && this.href.indexOf('shagadelic-groove.de/')<0){
  		location.href = this;			
	}
	
    if(this.href.indexOf(home)>=0&&this.href.indexOf('/wp-')<0&&this.href.indexOf('#')<0){
      event.preventDefault();
      // remove click border
      this.blur();
      // get caption: either title or name attribute
      var caption = this.title || this.name || "";
      // get rel attribute for image groups
      var group = this.rel || false;
      // display the box for the elements href
      if(!isRss){
      	loadPage(this.href, this);
      }
      return false;
    }
    
    
    return false;
  });

  $j("#newsletterForm").attr("action", "javascript:submitNewsletter('http://shagadelic-groove.de/wp/?wpnewsletter_name='+document.getElementById('wpnewsletter_name').value+'&wpnewsletter_email='+document.getElementById('wpnewsletter_email').value)");
 	
}
function getHTTPObject() {
  var xmlhttp;
if (window.XMLHttpRequest) {
  // If IE7, Mozilla, Safari, and so on: Use native object.
  xmlhttp = new XMLHttpRequest();
}
else
{
  if (window.ActiveXObject) {
     // ...otherwise, use the ActiveX control for IE5.x and IE6.
     xmlhttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
  }
}
  return xmlhttp;
}
var isWorking = false;
var http = getHTTPObject();

function loadPage(url, newItem){
  if(!isWorking){
    scroll(0,0);
    $j("#col1_content").html('<div id="heading"></div><center><img style="margin-top:50px;" src="'+loadingIMG.src+'" /></center>');
    http.open('GET',url,true);
    isWorking=true;
    http.onreadystatechange=showPage;
    http.send(null);
    

   // if(item.parentNode) {item.parentNode.className = item.parentNode.className.replace(/current_page_item/,"");}		//set back active menu element
  // 	item = newItem;
   // if(item.parentNode) {item.parentNode.className = item.parentNode.className+" current_page_item";}
  }
}
function submitNewsletter(param){
  if(!isWorking){
    scroll(0,0);
    $j("#col1_content").html('<div id="heading"></div><center><img style="margin-top:50px;" src="'+loadingIMG.src+'" /></center>');    http.open('GET',param,true);
    isWorking=true;
    isForm = 1;
    http.onreadystatechange=showPage;
    http.send(null);
 //		if(item.parentNode) {item.parentNode.className = item.parentNode.className.replace(/current_page_item/,""); } // set back active menu element
  }
}
function submitGb(){//////plugin....!!!!!!!!!!!!!
	var gburl = "http://shagadelic-groove.de/wp/?page_id=6";
 if(!isWorking){
 	isGb = 1;
 	var daten = $j('#gbForm').serialize();
    scroll(0,0);
    $j("#col1_content").html('<div id="heading"></div><center><img style="margin-top:50px;" src="'+loadingIMG.src+'" /></center>');
     $j.ajax({
   type: "POST",
   url: gburl,
   data: daten,
   success: function(msg){
     showPage(msg);
   }
 });  
    isWorking = true;
  }
}
function showPage(msg){	
  if(http.readyState==4){
    if(http.status==200){
      isWorking=false;
      if(isGb){
      	var content = msg;
      	isGb=0;
      }else{
      	var content = http.responseText;
      }
      //für newsletter
      if(isForm){
      	content = content.split('<img src="http://shagadelic-groove.de/wp/wp-content/themes/shag_yaml/images/Bilder/newsletter_txt.jpg" alt="newsletter">')[1];
      	content = content.split('<')[0];
        output = '<div id="heading"><h1 class="headingText">Newsletter</h1></div><div id="contentText">'+content+'</div>';
        isForm = 0;
      }else{
	      content = content.split('<div id="col1_content" class="clearfix">')[1];
	      content = content.split('<div id="col3">')[0];
	      var output = content;
     	}
    document.getElementById('col1_content').innerHTML=output;
    $j("a").unbind('click');
   	FLIR.replace(['h1.headingText']);
	FLIR.replace(['h2']);
      pageLoaderInit();
    }else{
      alert(http.status);
    }
  }
}
