var controller = 'ajaxslide';

function loadCategory(categoryId)
{
    
    var url = controller + '/category/id/' + categoryId;
    var contentArea = document.getElementById('contentArea');
    var loading = document.getElementById('loading');
    
    xmlHttp.open("GET", url);
    
    xmlHttp.onreadystatechange = function() {
    	if (xmlHttp.readyState > 0 && xmlHttp.readyState < 4) {
    		loading.style.visibility = 'visible';
    		loading.style.display = 'block';
    	}	
    		
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    		loading.style.visibility = 'hidden';
    		loading.style.display = 'none';
    		
            response = xmlHttp.responseText;  
            contentArea.innerHTML = response;         
        }
    }
    
    xmlHttp.send(null);
}

 function loadSubCategory(subCategId)
{
    
    var url = controller + '/subcategory/id/' + subCategId;
    var contentArea = document.getElementById('contentArea');
    var loading = document.getElementById('loading');
    
    xmlHttp.open("GET", url);
    
    xmlHttp.onreadystatechange = function() {
    	if (xmlHttp.readyState >= 0 && xmlHttp.readyState < 4) {
       	loading.style.visibility = 'visible';
    		loading.style.display = 'block';    
    	}
    	
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    		loading.style.visibility = 'hidden';
    		loading.style.display = 'none';
    		
            response = xmlHttp.responseText;            
            contentArea.innerHTML = response;          
        }
    }
    
    xmlHttp.send(null);
} 

function initLoading() {
	var loading = document.getElementById('loading');
	loading.style.visibility = 'visible';
	loading.style.display = 'block';


	
}

function getCategory(move, isHome, isChangeContent)
{
    
    if (move == 'back') {
        currentIndex = currentIndex - 1;
    } else if (move == 'forward') {
        currentIndex = currentIndex + 1;

    }     
    
    if (currentIndex < 0) {
        currentIndex = categoryCount - 1;
    }
    
    if (currentIndex >= categoryCount) {
        currentIndex = 0;
    }
    
    var url = controller + '/innerslide/id/' + categoryArray[currentIndex];

    if (isHome) {
        url += '/home/1';    
    }
       
	var loading = document.getElementById('loading');
	var arrowNote = document.getElementById('arrowNote');    

    if (!isHome) {
		
        xmlHttp.open("GET", url, false);
        xmlHttp.send(null);
        response = xmlHttp.responseText;    
        document.getElementById('slideContent').innerHTML = response;          
    	
        if (isChangeContent) {
        	loadCategory(categoryArray[currentIndex]);
        } else {
    		loading.style.visibility = 'hidden';
    		loading.style.display = 'none';        	
        }	
        
        
    } else {    	

    	
        xmlHttp.open("GET", url);
        
        xmlHttp.onreadystatechange = function() {
        	if (xmlHttp.readyState > 0 && xmlHttp.readyState < 4) {
        		loading.style.visibility = 'visible';
        		loading.style.display = 'block';
        		
        		arrowNote.style.visibility = 'hidden';
        		arrowNote.style.display = 'none';
        		
        	}
        	
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        		loading.style.visibility = 'hidden';
        		loading.style.display = 'none';
        		
        		arrowNote.style.visibility = 'visible';
        		arrowNote.style.display = 'block';
        		
                response = xmlHttp.responseText;
                document.getElementById('slideContent').innerHTML = response;          
            }
        }
        
        xmlHttp.send(null);    	
    }	
}

function getSlideNoCategory(move)
{
    
    if (move == 'back') {
        currentIndex = currentIndex - 1;
    } else if (move == 'forward') {
        currentIndex = currentIndex + 1;
    }     
    
    if (currentIndex < 0) {
        currentIndex = categoryCount - 1;
    }
    
    if (currentIndex >= categoryCount) {
        currentIndex = 0;
    }
    
    var url = controller + '/innerslide/id/' + categoryArray[currentIndex];

    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);
    response = xmlHttp.responseText;    
    document.getElementById('slideContent').innerHTML = response;
}
