
var slideshow = 'off';

var switchDelay = 24000;

function resizeTable()
{
    var height = $(document).height();
    var max = $('body').height();
    if(height > max)
    {
       $("#allBg").height(height);
    }
}

var currentId = 0;
function switchContent(direction, mode, id)
{
    if(direction === null)
    {
        direction = 1;
    }
	
    if(slideshow=='on' || mode == 'manual')
    {

     $.ajax({
      
      type: "GET",
      url: "/lv/?here",
      data: "op=" + direction + '&id=' + id,
      
      
      success: function(msg){
          var image = $("image", msg).text();
          var textual = $("text", msg).text();
          var id = $("id", msg).text();
              
            displaySlide(image, textual, id);
            
			currentId = id;
			
            if (mode == 'auto') 
            {
                setTimeout('switchContent(1, "auto")', switchDelay);
            }
            if (mode == 'manual') 
            {
                slideshow = 'off';
            }

           
      }
      
     
     });
     
    }
}

function displaySlide(image, text, id)
{
    $("#allBg").fadeOut(300, function(){
       
        $("#allBg").attr('style', 'background:url('+image+') no-repeat center center transparent;');
       
        resizeTable();
    });

    $("#allBg").fadeIn(600, function()
    {
        resizeTable();
    });
    
    var title = $('#title' + id).html();
    
    $('#titleHolder').html(title);
    $('#textHolder').html(text);
    
    document.location.href = document.location.pathname + '#' + id;
    jQuery(".num").removeClass("active");
    jQuery(".item"+id).addClass("active");
}

function resizeWindow()
{
    var hei = $(window).height();
    jQuery("#allBg").css('height', hei);
    jQuery("#overflow").css("height", hei);
}

var switchTimeout;
function manualSwitch(direction)
{
    slideshow = 'on';
    
	/* when normal navigation is fixed, this can be uncommented */
	/*
	  
	var offset = 1;
	if( direction == 0 )
	{
		offset = -1;
	}
	var modulus = jQuery( '.directNavigation > .num' ).length;
	if( modulus > 0 )
	{
		var pageNo = ( currentId * 1 + offset ) % modulus;
		if( pageNo < 0 ){ pageNo += modulus; }
		currentId = pageNo;
		clearTimeout( switchTimeout );
		switchTimeout = setTimeout(function()
		{
			// console.log( 'fired' );
			showItem( pageNo );
		}, 300);
	}
	else
	{
		// something's wrong - let's do the safe thing
		switchContent(direction, 'manual');
		return false;
	} 
	*/
    
	switchContent(direction, 'manual');
	return false;
	
	
}

function showItem(id)
{
    switchContent(1, 'manual', id);
    
    //hilite chosen
    jQuery(".num").removeClass("active");
    jQuery(".item"+(id-1)).addClass("active");
}

function changePage(direction)
{
    //alert(direction);
    $.ajax({
      
         type: "GET",
         url: "/lv/?getPage",
         data: "direction=" + direction,
         success: function(msg)
         {
             $("#slides").html(msg);
         }
      
     });
      
      
      
}

function removeBg()
{
    $("body").removeAttr('style');
}


jQuery(document).ready(function(){    

	//read hash
    var hash = self.document.location.hash.substring(1);
    if(hash!='')
    {
    	$('.item' + hash).click();
    }
	
    removeBg();    

    if(jQuery(".contentBox").height())
    {
    	var docH = jQuery(window).height();
    	var contentH = jQuery(".contentBox").height() + 240 + jQuery(".bottomInner").height(); // 240 - head+padding;
    	
    	if(contentH > docH)
    	{
    		//console.log(contentH);
    		jQuery("body").css("height", contentH);
    		jQuery("#overflow").css("height", contentH);
    	}
    	
    }
    
    jQuery("#overflow").click(function(){
    	document.location.href = "http://"+document.location.hostname;
    });
    
    
    
});


function readButtons()
{
/*
    $(".menuTextYellow").each(function(i){
    console.log(i);
    //button1 = this;
    //i.hide();
    //button2 = $(".counter").next("span");
    button1.hover(function(){
        console.log('fsd');
    });
        
       
    });
  */ 
}




