$(function()
{
    var hash=location.hash;
    
    var currentNav=null;
    
    if(hash=='')
    {
        currentNav= $('.side-column .user-menu li:eq(0)').addClass('active');
	    
        getInfo($('.side-column .user-menu li:eq(0)').attr('id').replace('Nav',''))
    }
    else
    {
         $('.side-column .user-menu li a').each(function()
         {
             if($(this).html()==hash.replace('#',''))
             {
                currentNav= $(this).parent().addClass('active');

                getInfo($(this).parent().attr('id').replace('Nav',''));
             }
         });
    }
    
    $('.side-column .user-menu li a').each(function()
    {
	    $(this).click(function()
	    {
	        currentNav.removeClass('active');
	        
	        currentNav=$(this).parent().addClass('active');
	        
	        id=$(this).parent().attr('id').replace('Nav','');
	        
	        var url=location.pathname.toLowerCase();
	        
	        if(url.indexOf('fleet.aspx')!=-1)
	            $('#ctl00_AdminToolbar1_lbnManage').attr('href','Governor/Info.aspx?Id='+id+'&width=961&height=622');
	        
	        getInfo(id);
	    });
    });
});

function getInfo(id)
{
    $('#info-column').html($('<img style="margin: 150px 0pt 0pt 300px;" src="images/loading.gif"/>'));
    
    var url=location.pathname.toLowerCase();
    
    $.ajax({
            url: 'AJAX/GetInfo.aspx?Id='+id,
            type: 'GET',
            dataType: 'html',
            timeout: 1000,
            success: function(html)
            {
                $('#info-column').html(html);
                
                initEventPhoto();
//                //Event Photo;
//                if(url.indexOf('eventphoto.aspx')!=-1)
//                    initEventPhoto();
//                
//                //Fleet;
//                if(url.indexOf('fleet.aspx')!=-1)
//                    initFleet();
            }
        });
}

function initEventPhoto()
{
    var imgCount=$('#imgBox img').length;
    var imgIndex=0;
    
    $('#imgBox').css('width',imgCount*154+'px');
    
    $('#imgBox li').each(function(){
	    $(this).css('margin','0').css('width','154px');
    });
    
    
    $('#imgBox li img').each(function(){
	    $(this).css('cursor','pointer').click(function(){
	    
	        var src=$(this).attr('src').replace('148_80_','682_368_');
	        
	        $("#place").fadeOut("slow",function()
	        {
	             $('#place').attr('src',src);
	        }); 
	        
	        $("#place").fadeIn("slow");
	        
	        $('#PhotoDescriptionPanel').html($(this).parent().find('div').html());
	    });
    });
    
    
    $('#btnNext').click(function()
    {
        var left=parseInt($('#imgBox').css('left').replace('px',''));
        
        if(left<=-imgCount*154+154||imgCount<=4||(left<=(4-imgCount)*154))
        { 
            return false;
//            left=154;
        }
        else
        {
            imgIndex++;
        }
       
        $('#imgBox').animate({left:(left-154)},800);
        
        return false;
    });
    
    $('#btnPrevious').click(function()
    {
        var left=parseInt($('#imgBox').css('left').replace('px',''));
        
        if(left>=462||imgCount<=4||left>=0) 
        {
            return false;
//            left=-154;
        }
        
        $('#imgBox').animate({left:(left+154)},800);
        
        return false;
    });
    
    $('#btnGetAQuote').click(function()
    {
        location.href='Quote.aspx?i='+escape($('#place').attr('src'));
        return false;
    });
}

function initFleet()
{
    $('.gallery-area .gallery-hold li img').each(function(){
	    $(this).css('cursor','pointer').click(function(){
	    
	        var src=$(this).attr('src').replace('148_80_','682_368_');
	        
	        $("#place").fadeOut("slow",function()
	        {
	             $('#place').attr('src',src);
	        }); 
	        
	        $("#place").fadeIn("slow");  
	    });
    });
    
    $('#btnGetAQuote').click(function()
    {
        location.href='Quote.aspx?i='+escape($('#place').attr('src'));
        return false;
    });
}