var currentTab="";
var previousTab="";
var currentSubTab ="";
var previousSubTab ="";
var currentTheme="";
var previousTheme="";


function ajaxLoad(link, lediv,callback){
	var args = ajaxLoad.arguments;
	var paramLink = args[0];
	var params = paramLink.substr(paramLink.indexOf('?')+1,paramLink.length);
	var link = paramLink.substr(0,paramLink.indexOf('?'));
	var lediv = args[1];
	$.ajax({
		type: "POST",
		url: link,
		data: params,
		dataType: "html",
		async: true,
		cache: false,
		global: true,
		success: function(html){
			$("#" + lediv).html(html);
			if(callback){
				callback();
			}
		}
	});
}

function changeTab(selectedTab,subTab,theme){	
	if(currentTab!=""){
		previousTab=currentTab;
	}
	currentTab=selectedTab;
	currentSubTab=subTab;
	currentTheme=theme;
	loadPage('tab');
}

function changeSubTab(subTab,theme){
	currentSubTab=subTab;
	currentTheme=theme;
	loadPage('subtab');
	
}

function changeTheme(theme){
	currentTheme=theme;
	loadPage('themes');
}

function loadPage(mode){
	if (mode=='tab'){
		ajaxLoad('navigation/tab.jsp?selectedTab='+currentTab,'top-menu');
		ajaxLoad('navigation/sidebar.jsp?selectedTab='+currentTab+'&subTab='+currentSubTab,'nav2');
		if (currentTab!='equalizer'){
			if (currentTab != 'press'){
				ajaxLoad(currentTab+'/left_'+currentTab+'.jsp?theme='+currentTheme,'nav');
			}else{
				ajaxLoad('profile/left_profile.jsp?theme='+currentTheme,'nav');
			}
			if(currentTab=='home'){
				ajaxLoad(currentTab+'/'+currentTab+'_'+currentTheme+'.jsp?','home-text');
				ajaxLoad(currentTab+'/'+currentTab+'_'+currentTheme+'_main.jsp?','featureList');
			}else if (currentTab == 'news' ){
				ajaxLoad('profile/profile_'+currentTheme+'.txt?','about-content');
			}else if (currentTab == 'press'){
				ajaxLoad('profile/profile_'+currentTheme+'.jsp?','about-content');
			}else{
				ajaxLoad(currentTab+'/'+currentTab+'_'+currentTheme+'.jsp?','about-content');
			}
			if (currentTab == 'press'){
				ajaxLoad('profile/profile_'+currentTheme+'_list.jsp?','header-content');
			}else{
				ajaxLoad(currentTab+'/'+currentTab+'_'+currentTheme+'_list.jsp?','header-content');
			}
			if(currentTab=='home'){
				ajaxLoad('profile/profile_news.txt?','newsticker',function(){
					
					$("#newsbig").click(function(){
						loadImage('news');
					});
					
					$("#newsticker").click(function(){
						loadImage('news2');
					});
					
					$("#newsticker,#newsbig").css('cursor', 'pointer');
					
					var i=0;
					$('#newsticker li:gt(5)').remove();

					$("#bigPress").click(function(){
						loadImage('press');
					});
					
					$("#pressTicker li div.listall").click(function(){
						loadImage('press2');
					});
					
					$("#newsticker").jCarouselLite({
						//btnGo: ["","","","","",".prev"],
						//btnPrev: ".next",
						btnNext: ".next",
						btnPrev: ".prev",
						visible: 1,
						vertical: true
					})//.css('height','100px');
					
				});
				ajaxLoad('profile/profile_press_list.jsp?','pressTicker',function(){
					
					$("#bigPress").click(function(){
						loadImage('press');
					});
					
					$("#pressTicker li div.listall").click(function(){
						loadImage('press');

					});
					
					$("#pressTicker,#bigPress").css('cursor', 'pointer');
					
					var i=0;
					$('#press2,#press3').remove();
					$('#press li:gt(5)').remove();
					
					$("#pressTicker").jCarouselLite({
						btnGo: ["","","","",".prevPress"],
						btnPrev: ".nextPress",
						visible:2,
						vertical: true
					});
					
				});
			}else{
				if (currentTab == 'press'){
					ajaxLoad('profile/profile_'+currentTheme+'_screen.jsp?','eqPicture');
				}else{
					ajaxLoad(currentTab+'/'+currentTab+'_'+currentTheme+'_screen.jsp?','eqPicture');
				}
			}
		}else {
			ajaxLoad(currentTab+'/'+currentSubTab+'/left_'+currentSubTab+'.jsp?theme='+currentTheme,'nav');
			ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'.jsp?','about-content');
			ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_list.jsp?','header-content');
			ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_screen.jsp?','eqPicture');
			ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_main.jsp?','mainFeature');
		}
	}
	if(mode=='subtab'){
		ajaxLoad('navigation/sidebar.jsp?selectedTab='+currentTab+'&subTab='+currentSubTab,'nav2');
		if (currentTab!='equalizer'){
			ajaxLoad(currentTab+'/left_'+currentTab+'.jsp?theme='+currentTheme,'nav');
			ajaxLoad(currentTab+'/'+currentTab+'_'+currentTheme+(currentTheme=='news' ? '.txt?' : '.jsp?'),'about-content');
			ajaxLoad(currentTab+'/'+currentTab+'_'+currentTheme+'_list.jsp?','header-content');
			ajaxLoad(currentTab+'/'+currentTab+'_'+currentTheme+'_screen.jsp?','eqPicture');
		}else {
			ajaxLoad(currentTab+'/'+currentSubTab+'/left_'+currentSubTab+'.jsp?theme='+currentTheme,'nav');
			ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'.jsp?','about-content');
			ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_list.jsp?','header-content');
			ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_screen.jsp?','eqPicture');
			ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_main.jsp?','mainFeature');
		}
	}
	if (mode=='themes'){
		ajaxLoad(currentTab+'/'+currentSubTab+'/left_'+currentSubTab+'.jsp?theme='+currentTheme,'nav');
		ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'.jsp?','about-content');
		ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_list.jsp?','header-content');
		ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_screen.jsp?','eqPicture');
		ajaxLoad(currentTab+'/'+currentSubTab+'/'+currentSubTab+'_'+currentTheme+'_main.jsp?','mainFeature');

	}
	if (currentTab!='home'){
		$("#about-content").show();
		$("#home-text").hide();
		$(".carouselColumn").hide();
		if(currentTab=='equalizer'){
			$("#mainFeature").show();
			$("#featureList").hide();
		}
		else{
			$("#mainFeature").hide();
			$("#featureList").hide();
		}
		$("#eqPicture").show();
		$('#nav2').css("background-color","#f2f2f2");
	}else{
		$("#home-text").show();
		$(".carouselColumn").show();
		$("#featureList").show();
		$("#mainFeature").hide();
		$("#eqPicture").hide();
		$("#about-content").hide();
		$('#nav2').css("background-color","#abacb0");
	}
}


function loadImage(div){
	if (div=="news"){
		$('#newsbig').colorbox({href:"profile/profile_news.txt"});
	}else if (div=="news2"){
		$('#bignews2').colorbox({href:"profile/profile_news.txt"});
	}else if (div=="press"){
		$('#bigPress').colorbox({href:"profile/profile_press_list.jsp"});
	}else if (div=="press2"){
		$('#pressTicker').colorbox({href:"profile/profile_press_list.jsp"});
	}else{
		$("a[rel='example1']").colorbox();
	}
}


