function mobileRedirect(){
    var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
    if (mobile) {
    var url =  document.URL; 
      if(url.indexOf("mobile")<0){
        if(url.indexOf("home")>0){
           document.location = "http://www.kandasoft.com/mobile.html"; 
        }else{
          document.location = "http://www.kandasoft.com/mobile"+ document.URL.substring(document.URL.indexOf("kandasoft.com")+13);
        }
      } 
      
    }  
}
/*
var selectedIndex = 0;
var visibility = 0.4;
var intervalValue = null;
var run = new Boolean("true");
 var styleArr = new Array(
   '/dms/templating-kit/themes/kandasoft/img/animation/background1-center.jpg',
  '/dms/templating-kit/themes/kandasoft/img/animation/background2-center.jpg',
  '/dms/templating-kit/themes/kandasoft/img/animation/background3-center.jpg',
  '/dms/templating-kit/themes/kandasoft/img/animation/background4-center.jpg'
 );
 
 var bgStyleArr = new Array(
  '/dms/templating-kit/themes/kandasoft/img/animation/background1.jpg',
  '/dms/templating-kit/themes/kandasoft/img/animation/background2.jpg',
  '/dms/templating-kit/themes/kandasoft/img/animation/background3.jpg',
  '/dms/templating-kit/themes/kandasoft/img/animation/background4.jpg'
 
 );
 var preloadArr = new Array(); 
function startAnimation(){
 for (i=1;i<5;i++)
 {
     preloadArr[i-1] = new Image();
     preloadArr[i-1].src = styleArr[i-1];
   
     init(i);
     
     
 }
   initMenuButtons();
   $("#item1").click();
   $("#spotlight-"+ Math.round(Math.random() * 5 +1)+"-header").click();
   
}
 
  $(window).load(
    function(){
    intervalValue = setInterval(function() {
      
         clickItemIndex(Math.round(Math.random() * 3 +1));
        }, 4000);
   }
    );
  
  function init(itemIndex){
      $('#item'+itemIndex).bind('mouseenter', function (){
        $(this).fadeTo('fast','1');
        animateRectangle(itemIndex,"1","5px");
      });
    
     $('#item'+itemIndex).bind('mouseleave', function (){
      if(itemIndex != selectedIndex){       
        $(this).fadeTo('fast',visibility);
        animateRectangle(itemIndex,"0","10px");
        }
     });  
     
    $('#item'+itemIndex).bind('click', function(){
      clickItemIndex(itemIndex);
    });
    
  }
  
  function clickItemIndex(itemIndex){
      if(selectedIndex != itemIndex){
        $('#animation-menu').animate({opacity: 0}, 1000, function(){
               $(this).css('background','url(' + styleArr[itemIndex-1] +') no-repeat');
               $('#stage').css('background','url('+ preloadArr[itemIndex-1].src+') repeat-x');
               $('#displaying-content').html($('#content'+itemIndex).html());
               }).animate({opacity: 1}, 1000);  
         $('#item'+selectedIndex).fadeTo('fast',0.4);
         $('#item'+itemIndex).fadeTo('fast',1);
         animateRectangle(selectedIndex,"0","10px");
         animateRectangle(itemIndex,"1","10px");          
      }
      selectedIndex = itemIndex; 
  }
  
  

   
   function initMenuButtons(){ 
   $('#forward').bind('click',function(){
       if(selectedIndex>=4){
         itemIndex = 1;
       }else{
         itemIndex = selectedIndex+1;
       }
       $('#item'+itemIndex).click();
       clearInterval(intervalValue);
       intervalValue = setInterval(function() {
         clickItemIndex(Math.round(Math.random() * 3 +1));
        }, 4000);
   });
   
   $('#back').bind('click',function(){
     if(selectedIndex == 1){
         itemIndex = 4;
       }else{
         itemIndex = selectedIndex-1;
       }
       $('#item'+itemIndex).click();
       clearInterval(intervalValue);
       intervalValue = setInterval(function() {
         clickItemIndex(Math.random()*3 +1);
        }, 4000);
   });
     
     $('#stop').bind('click',function pause() {
       clearInterval(intervalValue);
      });  
  } 
 
function animateRectangle(index, opacityValue, marginValue){
  $('#item'+index).children(':first').animate({
    opacity: opacityValue,  
   }, 'fast' );
}

    var image1 = $('<img />').attr('src','/dms/templating-kit/themes/kandasoft/img/animation/background1-center.jpg');
    var image2 = $('<img />').attr('src','/dms/templating-kit/themes/kandasoft/img/animation/background2-center.jpg');
    var image3 = $('<img />').attr('src','/dms/templating-kit/themes/kandasoft/img/animation/background3-center.jpg');
    var image4 = $('<img />').attr('src','/dms/templating-kit/themes/kandasoft/img/animation/background4-center.jpg');
*/    
    var selectedIndex = 1;
    var itemIndex = 1;
    var visibility = 0.4;
    var intervalValue;
    function playAnimation(){
      intervalValue = setInterval(function() { 
      itemIndex++;
      if(itemIndex > 4){
        itemIndex = 1;
      }
      smoothBackgroundChange(itemIndex);  
      }, 5000);
    }
    
    function initAnimation(){
       for(i=1; i<=4; i++){
         initItem(i);
       }   
    }
    
    function initItem(index){  
      $('#item'+index).click(function(){
        clearInterval(intervalValue);
        smoothBackgroundChange(index);
        playAnimation();  
      });
      
      $('#item'+index).bind('mouseenter', function (){
        $(this).stop().fadeTo('fast','1');
        animateRectangle(index,"1","5px");
      });
    
      $('#item'+index).bind('mouseleave', function (){
        if(index != selectedIndex){       
        $(this).stop().fadeTo('fast',visibility);
        animateRectangle(index,"0","10px");
      }
      });   
    }
    
    function smoothBackgroundChange(index){
      itemIndex = index;
      if(selectedIndex !== itemIndex){
       $('#content'+selectedIndex).stop(true).animate({
        opacity: 0,
        }, 300, function() {            
       });   
       
        $('#item'+selectedIndex).fadeTo('fast',0.4);
              $('#item'+itemIndex).fadeTo('fast',1);
              animateRectangle(selectedIndex,"0","10px");
        
       $('#outer').addClass("bg"+itemIndex).removeClass("bg"+selectedIndex);
       $('#inner').fadeOut('slow', function(){
          $('#inner').addClass("bg"+itemIndex).removeClass("bg"+selectedIndex);
          $('#inner').fadeIn('slow');
          $('#content'+itemIndex).animate({
            opacity: 1
            }, 200, function() {});
         selectedIndex=itemIndex;      
      
      });
      animateRectangle(itemIndex,"1","10px");   
  
      
    }
    }
    function animateRectangle(index, opacityValue, marginValue){
      $('#item'+index).children(':first').stop().animate({
      opacity: opacityValue,  
      }, 'fast' );
    }
