$(document).ready(function() {
    getCookie();
   

});

var _slider;
var arrWorkList=new Array();
var tempFirstLiContent;

//int the work page,click the related work.if the workidlist is null,will get the data.
function getRelatedWorkContentById(workId,pageType){
  $("#mainBody").hide();
  if($.cookie('WorkIdList'))
  {
    getWorkContentById(workId,pageType);
  }
  else
  {
    getWorkList("/getallworklist.aspx",workId,pageType);
  }
}
function getRelatedPeopleContentById(peopleId,pageType){
   $("#mainBody").hide();
  if($.cookie('PeopleIdList'))
  {
    getPeopleContentById(peopleId,pageType);
  }
  else
  {
    getPeopleList("/getallpeoplelist.aspx",peopleId,pageType);
  }
}
//get work list
function getWorkList(url,workId,pageType)
{
  $.ajax({
    type: "GET",
    dataType: 'html',
    url: url,
    cache: false,
    success: function(list)
    {
       if($.trim(list).length > 0)
       {
           list=list.substring(0,$.trim(list).length-1);
           var hostName='.profero.com';//document.location.host;
           $.cookie("WorkIdList", null);
           $.cookie("WorkIdList",list,{expires:1,path:'/',domain:hostName,secure:false});
         
           getWorkContentById(workId,pageType);
       }
    }
  });
}
function getPeopleList(url,peopleId,pageType)
{
  $.ajax({
    type: "GET",
    dataType: 'html',
    url: url,
    cache: false,
    success: function(list)
    {
       if($.trim(list).length > 0)
       {
           list=list.substring(0,$.trim(list).length-1);
           var hostName='.profero.com';//document.location.host;
           $.cookie("PeopleIdList", null);
           $.cookie("PeopleIdList",list,{expires:1,path:'/',domain:hostName,secure:false});
         
           getPeopleContentById(peopleId,pageType);
       }
    }
  });
}
//get work 
function getWorkContentById(workId,pageType){
  //I'm viewing work page,when I'll go to people page,remove content and create it.
  if(pageType == $("#pageType").text())
  {
      //if work list is exist,don't reload content and go to the selected work page.
      WorkNavgation($.cookie("WorkIdList"),workId,"/getawork.aspx",'false');
    
      //show animate
      ShowContent();
  }
  else
  {
      GetIdListFromCookie("WorkIdList",workId,"/getawork.aspx");
  }
  
  scroll(0,0);
}

// get people
function getPeopleContentById(peopleId,pageType){
  
  //I'm viewing people page,when I'll go to work page,remove content and create it.
  if(pageType == $("#pageType").text())
  {
      //if people list is exist,don't reload content and go to the selected people page.
      WorkNavgation($.cookie("PeopleIdList"),peopleId,"/getaperson.aspx",'false');
      
      //show animate
      ShowContent();
  }
  else
  {
     GetIdListFromCookie("PeopleIdList",peopleId,"/getaperson.aspx");
     ShowContent();
  }
}

// get story
function getStoryContentById(_storyIdList,_storyUrlList){

    var _arrIdList = [];
    var _arrUrlList = [];
    var _arrList = [];
    var idListLength=0;
  
    if(_storyIdList){
      _arrIdList = _storyIdList.split(',');
    }
  
    if(_storyUrlList){
      _arrUrlList = _storyUrlList.split(',');
    }
    
    
    var _index=0;
     $.each(_arrIdList,function(){
       if(this!=""){
         _arrList[_index]=this; 
         if(_index != 0)
         {
           idListLength++;
         }
         _index++;
       }
     });
  
     $.each(_arrUrlList,function(){
       if(this!=""){
         _arrList[_index]=this; 
         _index++;
       }
     });
    
    if(_arrList.length > 0)
    {
      CreateStoryLi(_arrList,idListLength);
    }
   
}

function GetXml(_li,_url,_id)
{
  $("#loadingPage").show();
    $.ajax({          
    type: "GET",
    dataType: 'html',
    url: _url,
    data:{"id":_id.toString()},
    cache: false,
    success: function(html){
        $("#mainBody").hide();
        $("#loadingPage").hide();
        $(_li).html(html);
        $("<scri"+"pt>"+"").attr({src:'/scripts/footerControl.js',type:'text/javascript',id:'footer'}).appendTo($('head'));              
   }
  });
}

function CreateStoryLi(_arrList,idListLength)
{
  var _url = document.location.href;
  
  for (i =0; i < _arrList.length ; i++)
  {
    if(i == 0)
    {
      var headLine=_arrList[i].split('-')[0];
      var subLine=_arrList[i].split('-')[1];
      
      var _html="<div id=\"indexPage\" class=\"indexPage\">";
          _html+=" <h3 class=\"tisaProBoldIta\" style=\"padding-top:10%;\"></h3>";
          _html+="<h3 class=\"tisaProBoldIta letterSpacing2\">"+headLine+"</h3>";
          _html+="<h3 class=\"tisaProBoldIta letterSpacing2\">"+subLine+"</h3>";
          _html+="</div>";
      
      tempFirstLiContent=_html;
      if(_url.indexOf("skip=0")<0)
      $("#slider1").append('<li id="WK'+i+'">'+_html+'</li>');      
      else $("#slider1").append('<li id="WK'+i+'">&nbsp;</li>');      
    }
    else
    {
       $("#slider1").append('<li id="WK'+i+'"> </li>');
    }
  }
  
  //to fix ipad bug
  var $slider = $('#slider1');
  var temppHtml =  jQuery("<p>").append($slider.eq(0).clone()).html();
  $slider.replaceWith('<div ><div class="bx-window" style="position:relative; overflow:hidden; ">' + temppHtml + '</div></div>');
  
  _slider = $('#slider1').bxSlider({
    storyArray:_arrList,
    pageType:'storyList',
    idListLength:idListLength,
    infiniteLoop: false,
    hideControlOnEnd: true
  });  
  
  Body = $(document.body);
  Setup.init();
  
  if(_url.indexOf("skip=0")>0 && _url.indexOf("#") == -1) {
    //_slider.goToSlide(0);
    $(".bx-next").click();
  }
  /*
  if($.cookie('hasViewed') == "1")
  {
      //if you had viewed this site,you will go to the camption 1
      if($.trim($("#slider1 #WK1").text()).length == 0)
      {
        if($.cookie('hasViewedStoryPage') == null || $.cookie('hasViewedStoryPage') == "")
        {
     setViewStoryCookie();
     window.setTimeout(function(){
             //I had clicked the next campaign before animation is showed,animation must be stoped.
             if($.trim($("#slider1 #WK1").text()).length == 0)
             {
               $(".bx-next").click();
             }
           },1000);
     
        }  
        else  
        {    
            //$("#slider1 #WK0 #indexPage").empty();
            //$(".bx-next").click();
            $("#pa").stop().css({top:"0"});
        }
        
      }
  }
  else 
  {
    _slider.goToSlide(0);
    
   if($("#slider1 li").length > 1)
   {
      //if story flow campaign count great than 1,will go to the second campaign 3 seconds later
      window.setTimeout(function(){
        //I had clicked the next campaign before animation is showed,animation must be stoped.
        if($.trim($("#slider1 #WK1").text()).length == 0)
        {
          $(".bx-next").click();
        }
      },1000);
   }
  }*/
}

function CreateStoryLiWithoutGoto(_arrList,idListLength)
{
  var _url = document.location.href;
  //clean slider1
  $("#pa .container").empty();
     var objHtml="<div class=\"pageContent\" id=\"wrapper\"><div class=\"dotted\" id=\"example\"><ul id=\"slider1\">";
     objHtml += "</ul></div></div>";
     $("#pa .container").html(objHtml);
  for (i =0; i < _arrList.length ; i++)
  {
    if(i == 0)
    {
      var headLine=_arrList[i].split('-')[0];
      var subLine=_arrList[i].split('-')[1];
      
      var _html="<div id=\"indexPage\" class=\"indexPage\">";
          _html+=" <h3 class=\"tisaProBoldIta\" style=\"padding-top:10%;\"></h3>";
          _html+="<h3 class=\"tisaProBoldIta letterSpacing2\">"+headLine+"</h3>";
          _html+="<h3 class=\"tisaProBoldIta letterSpacing2\">"+subLine+"</h3>";
          _html+="</div>";
      
      tempFirstLiContent=_html;
      if(_url.indexOf("skip=0")<0)
      $("#slider1").append('<li id="WK'+i+'">'+_html+'</li>');      
      else $("#slider1").append('<li id="WK'+i+'">&nbsp;</li>');      
    }
    else
    {
       $("#slider1").append('<li id="WK'+i+'"> </li>');
    }
  }
  //to fix ipad bug
  //var $slider = $('#slider1');
  //var temppHtml =  jQuery("<p>").append($slider.eq(0).clone()).html();
  //$slider.replaceWith('<div ><div class="bx-window" style="position:relative; overflow:hidden; ">' + temppHtml + '</div></div>');
  _slider = $('#slider1').bxSlider({
    storyArray:_arrList,
    pageType:'storyList',
    idListLength:idListLength,
    infiniteLoop: false,
    hideControlOnEnd: true
  });  
  Body = $(document.body);
  Setup.init();
  $("#pageType").html("");
}




function setViewStoryCookie()
{ 
    var hostName='.profero.com';
    $.cookie('hasViewedStoryPage',"1",{path:'/',domain:hostName,secure:false});  
}

//get work content by workId
function getStoryData(storyId,_url){
  $("#loadingPage").show();
  $.ajax({
    type: "GET",
    dataType: 'html',
    url: _url,
    data:{id:storyId},
    cache: false,
    success: function(html){
      $("#loadingPage").hide();
      var id="#WK"+storyId;
      if($(id).length > 0)
      {
          $(id).empty();
          $(id).html(html);
      }
    }
  })
}  

function GetIdListFromCookie(listName,curWorkId,_url)
{
  if($.cookie(listName) != null)
  {
    WorkNavgation($.cookie(listName),curWorkId,_url,'true');
  }
}

//set prev workid and next workid
function WorkNavgation(workList,workId,_url,_isReLoadContent)
{
  if(workList!=null)
  {
      var idList=[];
      var count=0;
      var currentIndex=-1;
    
      if(workList.indexOf('-')!=-1)
      {
        idList=workList.split("-");
        for(_index=0;_index < idList.length; _index++)
        {
           if(idList[_index]==workId)
           {
             currentIndex=count;
           }
           count=count+1;
        }
      }
      else
      {
        if(workList == workId)
        {
          currentIndex=0;
          count=1;
          idList[0]=workId;
        }
      }
      
      if(currentIndex != -1)
      {
        var tempWorkId="#WK"+idList[currentIndex];
        if(_isReLoadContent == 'true')
        {
          CreateDivs(idList,count,currentIndex,_url);
          
          GoSlide(currentIndex,_url,workList);
        }
        else
        {
          //if work page content is empty which you will go to view,must be create it.
         
          if($.trim($(tempWorkId).html()).length == 0)
          {
            getWorkData(idList[currentIndex],_url);
            if(_slider != null)
            {
              _slider.goToSlide(currentIndex);
            }
          }
          else
          {
            //to do
            var tempLi="#WK"+idList[currentIndex];
            workBackScroll(tempLi,idList[currentIndex]);
            
            if(_url == "/getawork.aspx")
            {
                changeUrl(idList[currentIndex],"work");
                document.title=$("#workTitle"+workId).text();
            }
            else if(_url == "/getaperson.aspx")
            {
                changeUrl(idList[currentIndex],"people");
                document.title=$("#peopleTitle"+workId ).text();
            }
            else
            {}
            
            
            if(_slider != null)
            {
              _slider.goToSlide(currentIndex);
            }
            //related work
            if($("#iddContentRelatedWork"+idList[currentIndex]).length > 0)
            {
                ScrollbarCommon(idList[currentIndex],"iddContentRelatedWork","scrollWorkContent","iddSliderRelatedWork","iddBarRelatedWork");
            }
          }
        }
        
        ShowAnchor(tempWorkId);
      }
     
   }
}
 
     
function changeUrl(_id,pageType)
{
  var locationUrl=window.location.href;

  if(pageType == "work")
  {
    if(locationUrl.indexOf("WId=") == -1)
    {
        if(locationUrl.indexOf("#") == -1)
        {
          locationUrl=locationUrl+"#WId="+_id;
        }
        else
        {
          locationUrl=locationUrl.substring(0,locationUrl.indexOf('#'));
          locationUrl=locationUrl+"#WId="+_id;
        }
        
        window.location.href=locationUrl;
    }
    else
    {
        locationUrl=locationUrl.substring(0,locationUrl.indexOf("WId="))+"WId="+_id;
        window.location.href=unescape(locationUrl);
    }
    urlHasChanged = true;
  }
  else if(pageType == "people")
  {
    if(locationUrl.indexOf("PId=") == -1)
    {
        if(locationUrl.indexOf("#") == -1)
        {
            locationUrl=locationUrl+"#PId="+_id;
        }
        else
        {
            locationUrl=locationUrl.substring(0,locationUrl.indexOf('#'));
            locationUrl=locationUrl+"#PId="+_id;
        }

        window.location.href=unescape(locationUrl);
       
    }
    else
    {
        locationUrl=locationUrl.substring(0,locationUrl.indexOf("PId="))+"PId="+_id;

        window.location.href=unescape(locationUrl);
       
    }
    urlHasChanged = true;
  }
  else if(pageType == "story")
  {
    if(locationUrl.indexOf("SId=") == -1)
    {
        if(locationUrl.indexOf("#") == -1)
        {
          locationUrl=locationUrl+"#SId="+_id;
        }
        else
        {
          locationUrl=locationUrl.substring(0,locationUrl.indexOf('#'));
          locationUrl=locationUrl+"#SId="+_id;
        }
        
        window.location.href=unescape(locationUrl);
    }
    else
    {
        locationUrl=locationUrl.substring(0,locationUrl.indexOf("SId="))+"SId="+_id;
        window.location.href=unescape(locationUrl);
    }
    urlHasChanged = true;
  }
  else
  {}
}

function CreateDivs(idList,_count,_index,_url)
{
   var pageType="";
   if(_url == "/getawork.aspx")
   {
     pageType="work";
   }
   else if(_url == "/getaperson.aspx")
   {
     pageType="people";
   }
   else
   {}
 
   if($("#slider1 li").length > 0)
   {
     $("#pa .container").empty();
     var objHtml="<div class=\"pageContent\" id=\"wrapper\"><div class=\"dotted\" id=\"example\"><ul id=\"slider1\">";
     for (i =0; i < _count ; i++)
     {
       objHtml += '<li id="WK'+idList[i]+'"> </li>';
     }
     objHtml += "</ul></div></div>";
     $("#pa .container").html(objHtml);
   }
    else
    {
      for (i =0; i < _count ; i++)
      {
        $("#slider1").append('<li id="WK'+idList[i]+'"> </li>');
      }
    }
  
   
   if(pageType != "")
   {
     $("#pageType").remove();
     $("<div/>").attr("id","pageType").html(pageType).css("display","none").insertAfter("#pa");
   }
     
   getWorkData(idList[_index],_url);
}

function ShowContent(){
    closeShowList();
    $("#storySlide").hide();
    $("#loadingPage").hide();
    $("#pa").show().animate( {top:"0"},{duration:4000,queue:true});
} 
    
//get work content by workId
function getWorkData(workId,_url){
  $("#loadingPage").show();
  $.ajax({
    type: "GET",
    dataType: 'html',
    url: _url,
    data:{"id":workId,"ajax":1},
    cache: false,
    async:false,
    success: function(html){

      closeShowList();
      $("#mainBody").hide();
      $("#loadingPage").hide();
      
      var id="#WK"+workId;
      if($(id).length > 0)
      {
          $(id).empty();
          $(id).html(html);
      }

      $("<scri"+"pt>"+"").attr({src:'/scripts/footerControl.js',type:'text/javascript',id:'footer'}).appendTo($('head'));
      
      if(_url == "/getawork.aspx")
      {
         //work page
         //related people
         
         //if($("#iddWorkRelatedPeople"+workId).length > 0)
         //ScrollbarCommon(workId,"iddWorkRelatedPeople","scrollPeopleContent","iddSliderRelatedPeople","iddBarRelatedPeople");
        
         //related work
         if($("#iddContentRelatedWork"+workId).length > 0)
         {
           ScrollbarCommon(workId,"iddContentRelatedWork","scrollWorkContent","iddSliderRelatedWork","iddBarRelatedWork");
         }
        
         changeUrl(workId,"work");
         workScroll(id,workId);
        
         setTwitterAndFacebook(workId);
        
         document.title=$("#workTitle"+workId).text();
        
        
         $(id+" .middleContent").each(function()
        {
            var _width=$(this).width();
            var _height=$(this).height();
          
            $(this).css({
              "top":"50%",
              "left":"50%",
              "margin-top":-(_height/2),
              "margin-left":-(_width/2)
            });
        });
        
        
      }
      else if(_url == "/getaperson.aspx")
      {
         //people page
         //related people
         /*if($("#iddContentPeopleInfo"+workId).length > 0)
         ScrollbarCommon(workId,"iddContentPeopleInfo","scrollContent","iddSliderPeopleInfo","iddBarPeopleInfo");*/
        
         //related work
         if($("#iddContentRelatedWork"+workId).length > 0)
         ScrollbarCommon(workId,"iddContentRelatedWork","scrollWorkContent","iddSliderRelatedWork","iddBarRelatedWork");
         SetLIWidth(id);
        
         workScroll(id,workId);
         changeUrl(workId,"people");
         Body = $(document.body);
         Body.addClass('blackBg');
        
         document.title=$("#workTitle"+workId).text();
      }
      
      
      
    }

  });
    

  $("#pa").show().animate( {top:"0"},{duration:1,queue:true});
  
} 
  
function SetLIWidth(_li)
{
    var width=$(document).width();//document.documentElement.clientWidth;

    if(width > 0)
    {
      $("#slider1 "+_li).width(width);
      $("#pa .bx-wrapper").width(width);
      $("#pa .bx-window").width(width);
      $("#pa #example").width(width);
    }
}
  
function setTwitterAndFacebook(_id)
{
   var pageTitle=document.title;
   var pageUrl=window.location.href;

   var twitterObj="#twitterSNS"+_id;
   var facebookObj="#facebookSNS"+_id;
  
   var facebookUrl="http://www.facebook.com/share.php?u="+pageUrl+"&t="+pageTitle;
   var twitterUrl="http://twitter.com/home?status="+pageUrl;

   if($(twitterObj).length > 0)
   {
     $(twitterObj).attr("href",twitterUrl);
   }

   if($(facebookObj).length > 0)
   {
     $(facebookObj).attr("href",facebookUrl);
   }
}
  
function ShowAnchor(_li)
{
     $("#slider1 .worklink").css("display","none");
   
     $(_li+" .worklink").css("display","block");
} 
  
  
function workBackScroll(_li,_id)
{
     var _count=$(_li+" .showContent").length;
     var contentH  = $("#pa .showContent").height()+120;
      if($("#pageType").text()=="people")
      {
        _count+=1;
        contentH = $(_li+" .peopleIntro").height();
      }

     
     
     var showName="#workAnchor"+_id;
  
     var _list="";
     for(i = 0; i < arrWorkList.length; i++)
     {
       if(String(_id) == String(arrWorkList[i][0]))
       {
         var newObj =new Array();
         newObj =arrWorkList[i];
         if(newObj[1] != null)
         {
           _list=newObj[1];
           break;
         }
       }
     }
      
     var tempList= "";
     if(_list != "")
     {
       //set ul height
       SetUlHeight(_li,contentH,_count);
       
       tempList=_list;
       
       $(showName).html(tempList[0].displayName);
       $(showName).attr("href","#"+tempList[0].anchorId);
       $(showName).removeClass("btnTop tisaProIta");
       $(showName).addClass("btn tisaProIta");
       
       window.onscroll = function ()
       {
             var scrollH  =  $(document).scrollTop();

             for(i = 0;i< _count; i++)
             {
                 if(scrollH >=0 && scrollH < (0.5 * contentH))
                 {
                     $(showName).html(tempList[0].displayName);
                     $(showName).attr("href","#"+tempList[0].anchorId);
                     $(showName).removeClass("btnTop tisaProIta");
                     $(showName).addClass("btn tisaProIta");
                     break;
                 }
                 else if(scrollH > (_count-1.5)*contentH && scrollH <= (_count-1)*contentH)
                 {
                     $(showName).html(tempList[_count-1].displayName);
                     $(showName).removeClass("btn tisaProIta");
                     $(showName).addClass("btnTop tisaProIta");
                     $(showName).attr("href","javascript:ChangeAnchorContent('"+showName+"','top"+_id+"','"+tempList[0].anchorId+"','"+tempList[0].displayName+"')");
                     break;
                 }
                else
                {
                   if(i >0 && i <= _count-2)
                   {
                       if(scrollH > (i-0.5)*contentH && scrollH <= (i+0.5)*contentH )
                       {
                           $(showName).html(tempList[i].displayName);
                           $(showName).attr("href","#"+tempList[i].anchorId);
                           $(showName).removeClass("btnTop tisaProIta");
                           $(showName).addClass("btn tisaProIta");
                           break;
                       }
                   }
                }
            }
        }
     }
}
  
function workScroll(_li,_id)
{
     var contentH  = $("#pa .showContent").height()+120;
       if(contentH  == 120) contentH = document.documentElement.clientHeight;
     var showName="#workAnchor"+_id;
      
         $(".tisaProIta").click(function(){
        
       });
       
    var _list;
    if($("#pageType").text()!="people")
    {
      _list=ScrollList;
    }
    else 
    {
      if($("#work" + _id).length >0)
      {
      _list="[{'index':1,'anchorId':'work"+_id +"','displayName':'Related Works'},{'index':2,'anchorId':'top"+_id +"','displayName':'Top'}]";
      }
      else 
      {
        _list="[{'index':1,'anchorId':'top'+_id,'displayName':'Top'}]";
      }
    }
     if(_list)
     {       
           var tempList= eval('(' + _list + ')');
             
           //if the the work's related work length equal 0,shoule be remove the related data in the json
           var _isRelatedWorkExist=false;
           
           var _tempLi="#work"+_id;

           _isRelatedWorkExist = (!isUlNull(_tempLi,"clearfix"));

           if(!_isRelatedWorkExist )
           {
             for(var j= 0; j < tempList.length; j++)
             {
               if(String(tempList[j].anchorId) == "work"+_id)
               {
                 tempList.splice(j,1);
                 break;
               }
             }
             //remove related work div
               delNullRelatedWork('work' + _id);
           }
           //store the work in the array
          storeWorkList(_id,tempList);
       
          //set ul height
          //SetUlHeight(_li,contentH,_count);
          SetUlHeight(_li,contentH,tempList.length); 
       
          if(!_isRelatedWorkExist)
          {
            //the work only has mini copy,the anchor button should be top
            if(tempList.length == 1)
            {
               $(showName).html(tempList[0].displayName);
               $(showName).attr("href","#"+tempList[0].anchorId);
            }
          }
          $("#slider1").get(0).onscroll = function ()
          {
            if( $("#slider1").scrollTop() != 0)
            {
              var ulScrollTop = $("#slider1").scrollTop();
              var docScrollTop = $(document).scrollTop();
              $(document).scrollTop(docScrollTop + ulScrollTop );
              $("#slider1").scrollTop(0);
            } 
          }
            
           $(showName).html(tempList[0].displayName);
           $(showName).attr("href","#"+tempList[0].anchorId);
           $(showName).removeClass("btnTop tisaProIta");
           $(showName).addClass("btn tisaProIta");
            
          window.onscroll = function ()
          {
               var scrollH  =  $(document).scrollTop();
               var divCount=tempList.length;
              
               for(i = 0;i< divCount; i++)
               {
                   if(scrollH >=0 && scrollH <= (0.5 * contentH))
                   {
                       $(showName).html(tempList[0].displayName);
                       $(showName).attr("href","#"+tempList[0].anchorId);
                       $(showName).removeClass("btnTop tisaProIta");
                       $(showName).addClass("btn tisaProIta");
                       break;
                   }
                   else if(scrollH > (divCount-1.5)*contentH && scrollH <= (divCount-1)*contentH)
                   {
                       $(showName).html(tempList[divCount-1].displayName);
                       $(showName).removeClass("btn tisaProIta");
                       $(showName).addClass("btnTop tisaProIta");
                       $(showName).attr("href","javascript:ChangeAnchorContent('"+showName+"','top"+_id+"','"+tempList[0].anchorId+"','"+tempList[0].displayName+"')");
                       break;
                   }
                  else
                  {
                     if(i >0 && i <= divCount-2)
                     {
                         if(scrollH > (i-0.5)*contentH && scrollH <= (i+0.5)*contentH )
                         {
                             $(showName).html(tempList[i].displayName);
                             $(showName).attr("href","#"+tempList[i].anchorId);
                             $(showName).removeClass("btnTop tisaProIta");
                             $(showName).addClass("btn tisaProIta");
                             break;
                         }
                     }
                  }
              }
          }
      }
}
   
//store the work in the array      
function storeWorkList(workId,workJson)
{
   //push every work scrolllist in the array.
   if(arrWorkList.length > 0)
   {
      var _isExist="0";
      for(_index = 0; _index < arrWorkList.length; _index++)
      {
        if(workId == String(arrWorkList[_index][0]))
        {
          _isExist="1";
          break;
        }
      }
     
      if(_isExist == "0")
      {
        var newObj =new Array(workId,workJson);
        arrWorkList.push(newObj);
      }
   }
   else
   {
      var newObj =new Array(workId,workJson);
      arrWorkList.push(newObj);
   }
}

function ChangeAnchorContent(obj,anchorId,newAnchorId,newAnchorName)
{
    window.location.href="#"+anchorId;
    $(obj).attr("href","#"+newAnchorId);
    $(obj).html(newAnchorName);
    
}
 
function isNumeric(obj)
{
  var reg ;
  if(/^[\d]+$/.test(obj)){
    return true;
  }
  else{
    return false;
  }
}  
      
//get workId by clientId
function getWork(clientId)
{
  $.ajax({
    type: "GET",
    dataType: 'html',
    url: '/getaworkbyclientid.aspx',
    data:{clientId:clientId},
    cache: false,
    success: function(workId)
    {
      if($.trim(workId) == "0")
      {
        var id="#Client"+workId;
        $(id).attr("href","javascript:void(0);");
      }
      else
      {
          GetIdListFromCookie("WorkIdList",workId,"/getawork.aspx");
      }
    }
  })     
}
 
function getFilter(){
    var industriesFilter="";
    var servicesFilter="";
  
    var url=window.location.href;
    var _indIndex=url.indexOf('indFilter=');
    var _serIndex=url.indexOf('serFilter=');
  
    if(_indIndex!=-1&&_serIndex!=-1)
    {
      var workUrl=$("#WorkUrl").text();
      showHeaderList('workList',workUrl);
    }
}

function SetCookie(id,nodeName,_url){
    var hostName='.profero.com';//document.location.host;
    
    //setViewStoryCookie();
    $.cookie('hasViewed',"1",{expires:7,path:'/',domain:hostName,secure:false});  
    $.cookie('PFLanguage',null,{expires:7,path:'/',domain:hostName,secure:false});
    $.cookie('PFStoryPath',_url,{expires:7,path:'/',domain:hostName,secure:false});
  
    if(id!=null){
        $.cookie('PFLanguage',id,{expires:7,path:'/',domain:hostName,secure:false});
    }

    if(nodeName!=null){
        $.cookie('PFLocal',nodeName,{expires:7,path:'/',domain:hostName,secure:false});
    }
    else{
        $.cookie('PFLocal','en',{expires:7,path:'/',domain:hostName,secure:false});
    }

    window.location=_url+"?skip=0";
}
      
function getStoryUrl(id){
  $.ajax({
    type: "POST",
    dataType: 'xml',
    url: '/storyurl.aspx',
    cache: false,
    data:{"lid":id},
    success: function(xml)
    {
      var _url = $(xml).find("value").text();
      if(_url.length>0)
      {
          var hostName='.profero.com';
        
          $.cookie('PFStoryPath',_url,{expires:7,path:'/',domain:hostName,secure:false});
        if((_url.indexOf(window.location.href) != -1 && window.location.href != _url) || window.location.href =="http://profero.com/")
           window.location.href=_url;
      }
     }
  })      
}


function getCookie()
{
  if($.cookie('hasViewed')!=null && $.cookie('hasViewed') =="1")
  {
       
  }
  //else
  //{
      setTimeout('show()',800);
  //}
}

function show()
{  
    if($(".locationList").length>0)
    {
    
    }
    else
    {
      //showLocation('locationList','/locationlist.aspx');
      if(window.location.pathname.length == 1)
      {
        $("#mainBody").css("position","relative");
        setTimeout('$("#mainBody").animate({top: -500},{duration:1000,complete:function(){goStory();}});',800);
      }
      
      //setTimeout('goStory()',800);
    }
}

  
function goStory()
{
    var hostName='.profero.com';
    //$.cookie('PFLanguage','1202',{expires:7,path:'/',domain:hostName,secure:false});
    if(!$.cookie('PFLanguage')) $.cookie('PFLanguage','1202',{expires:7,path:'/',domain:hostName,secure:false});
    
    $.cookie('hasViewed',"1",{expires:7,path:'/',domain:hostName,secure:false});

    getStoryUrl($.cookie('PFLanguage'));
    
}

function GoSlide(_index,_url,_idArray){
  _slider = $('#slider1').bxSlider({
    idArray:_idArray,
    pageType:'',
    URL:_url,
    infiniteLoop: false,
    hideControlOnEnd: true
  });  
  Body = $(document.body);
  Setup.init();
    _slider.goToSlide(_index);
}

 function isUlNull(keyId,ulCla){
  
  var curUl =$("#slider1 " + keyId + " ." + ulCla);

  if(curUl == null || curUl.length == 0 || curUl.children().length == 0)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function SetUlHeight(_li,conentHeight,conentCount)
{
    //slider1 is UL'Id
    
    if($("#pa #slider1").length > 0)
    {
      var height=conentHeight * conentCount;

      $("#pa #slider1").height(height);
      
      var width=document.documentElement.clientWidth;

      if(conentCount == 1)
      {
        if(width > 0)
        {
          $("#slider1 "+_li).width(width);
          $("#pa .bx-wrapper").width(width);
          $("#pa .bx-window").width(width);
          $("#pa #example").width(width);
        }
      }
      else
      {
          $("#pa .bx-wrapper").width(width);
          $("#pa .bx-window").width(width);
          $("#pa #example").width(width);
      }
    }
}
    
function delNullRelatedWork(keyId){
  $("#"+keyId).remove();
  //remove bg img
  $("#" + keyId.replace("work","relatedworkbg")).remove();
} 

 function StopVideo(sliderFlg){
    var currentLiNo ;
    if(sliderFlg == null){ currentLiNo = _slider.getCurrentSlide();}
    else if(sliderFlg) {currentLiNo = _slider.getCurrentSlide() + 1;}
    else {currentLiNo = _slider.getCurrentSlide() - 1;}

    if( $(".pager ").eq(currentLiNo).find(".showVideo video, .showVideo object, .showVideo embed").length > 0)
    {
    var videoFlg = false;
    if(!!document.createElement('video').canPlayType)
    {
      /*var vidTest=document.createElement("video");
      var h264Test=vidTest.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
      if (!h264Test)
      {
        videoFlg = false;
      }
      else
      {
        videoFlg = true;
      }  */    
      videoFlg = true;
    }
    else
    {
      videoFlg = false;
    }
    if(videoFlg )
          {
              $(".pager ").eq(currentLiNo).find("video").each(function(){
                  this.pause();
              });
          }
          else
          {
              $(".pager ").eq(currentLiNo).find("object").each(function(){
                  jwplayer($(this).attr('id')).stop();
              });
          }
    }
  }

function setBuAnchor()
{
  var liCount = $("#mainBody .content .showContent").length;
  if(liCount == 0)
  {
    $("#mainBody .content").hide();
  }
  else if(liCount == 1)
  {
    $("#mainBody .content").height(document.documentElement.clientHeight );
     if($("#mainBody .content .showContent").attr('id') == 'people')
     {
        $("#workAnchor").html($("#anchorDicHid").val().split(',')[1]);
        $("#workAnchor").attr("href","#people");
        $("#workAnchor").removeClass("btnTop tisaProIta");
        $("#workAnchor").addClass("btn tisaProIta");
     }
    else
    {
        $("#workAnchor").html($("#anchorDicHid").val().split(',')[0]);
        $("#workAnchor").attr("href","#work");
        $("#workAnchor").removeClass("btnTop tisaProIta");
        $("#workAnchor").addClass("btn tisaProIta");
    }
  }
  window.onscroll = function ()
  {
    var contentH  = $(".showContent").height()+120;
    var showName="#workAnchor";
    var scrollH = $(document).scrollTop();
    var divCount=1;
    var tempList = eval('([{displayName:"",anchorId:""},{displayName:"",anchorId:""},{displayName:"",anchorId:""}])');
    var conIndex = 0;
    var anchorNameList = $("#anchorDicHid").val().split(',');
    $.each($("#mainBody .content .showContent"),function(){
      if($(this).find('ul li').length >0)
      {
        divCount += 1;
        if($(this).attr('id') == 'work')
        {
          tempList[conIndex].displayName = anchorNameList[0];
          tempList[conIndex].anchorId = 'work';
        }
        if($(this).attr('id') == 'people')
        {
          tempList[conIndex].displayName = anchorNameList[1];
          tempList[conIndex].anchorId = 'people';
        }
        conIndex += 1;
      }
    });
    tempList[conIndex].displayName = anchorNameList[2];
    tempList[conIndex].anchorId = 'articleContent';
    
  
    for(i = 0;i< divCount; i++)
    {
      if(scrollH >=0 && scrollH <= (0.5 * contentH))
      {
        $(showName).html(tempList[0].displayName);
        $(showName).attr("href","#"+tempList[0].anchorId);
        $(showName).removeClass("btnTop tisaProIta");
        $(showName).addClass("btn tisaProIta");
        break;
      }
      else if(scrollH > (divCount-1.5)*contentH && scrollH <= (divCount-1)*contentH)
      {
        $(showName).html(tempList[divCount-1].displayName);
        $(showName).removeClass("btn tisaProIta");
        $(showName).addClass("btnTop tisaProIta");
        $(showName).attr("href","javascript:ChangeAnchorContent('"+showName+"','top','"+tempList[0].anchorId+"','"+tempList[0].displayName+"')");
        break;
      }
      else
      {
        if(i >0 && i <= divCount-2)
        {
          if(scrollH > (i-0.5)*contentH && scrollH <= (i+0.5)*contentH )
          {
            $(showName).html(tempList[i].displayName);
            $(showName).attr("href","#"+tempList[i].anchorId);
            $(showName).removeClass("btnTop tisaProIta");
            $(showName).addClass("btn tisaProIta");
            break;
          }
        }
      }
    }
  }
}
  
var statusmsg=""
function hidestatus(){
   window.status=statusmsg
return true
}
  
$(function(){
 $("a").hover(function(){hidestatus();});
})
