var $j = jQuery.noConflict();
var $rotator, $currentRotatorIndex = 0, $fItemsCount, $stopAfterAll = 0, $fItemWidth, $scrollTo; 



$j(document).ready(function(){ 

$j('div.rhs_push_box:last').addClass('last');

$j("#queries_general_query").focus(function(){
    if($j(this).val() == 'Type search here...')
      {
        $j(this).val('');
      }
  });

$j("#queries_general_query").blur(function(){
    if($j(this).val() == '')
      {
        $j(this).val('Type search here...');
      }
  });

$j('a.external_link').click(function()
{
     this.target='_blank';
});

$j('#content_col div table').each(function() {

$j(this).find('thead tr th:first').addClass('first_col');
$j(this).find('thead tr th:last').addClass('last_col');

});


    
$j('a.print_ico').click(function()
{
     this.target='_blank';
});

    rotatorPreSetup();
    $rotator = setInterval("rotateFeaturedItems('auto')", 4000); 
/*
$j('#lhs_column ul li').hover(function(){
$j(this).children('a').addClass('over');
}, function(){
$j(this).children('a').removeClass('over');
});
*/

$j('#content_col table').each(function(){
    $j(this).find('tr:even').addClass('even');
});


});

function rotatorPreSetup()
  { 
    // stop rotation on click
    $j(".feature_box").click(function(){
        clearInterval($rotator);
      });
	
    // feature items object 
    var $fItems = $j("#content_col .rotate");
    
	// item width
	$fItemWidth = $j("#content_col .items .feature_item").width();

    // count f items 
    $fItemsCount = $fItems.length; 
   
    // hide all feature items but first 
    //$j("#content_col .feature_item:gt(0)").hide(); 

    // add nav links under f items  
    $fNav = $j("#content_col .feature_nav"); 

    if($fItemsCount > 1)
      {
        $fNav.append("<a id='feature_prev' href='#'>Prev</a>"); 
        for(var $i = 0; $i < $fItemsCount; $i++)
          {
            $fNav.append("<a class='dot' href='#'>" + $i + "</a>");
          }
        $fNav.append("<a id='feature_next' href='#'>Next</a>");
      } 

    // set first nav link 
    $j(".feature_nav a.dot:eq(" + $currentRotatorIndex + ")").addClass("current"); 

    // click events on f items nav 
    $j("#feature_prev").click(function(e){
        e.preventDefault(); 
        clearInterval($rotator); 
        rotateFeaturedItems('prev'); 
      });

    $j("#feature_next").click(function(e){
        e.preventDefault(); 
        clearInterval($rotator); 
        rotateFeaturedItems('next'); 
      }); 

    $j(".feature_nav .dot").click(function(e){ 
        e.preventDefault(); 
        clearInterval($rotator); 
        rotateFeaturedItems('dot', $j(".feature_nav .dot").index($j(this))); 
      }); 
  } 

function rotateFeaturedItems($mode, $dotIndex)
  { 
    // if current dot index is equal all dots number set index = 0 
    if($mode == 'auto') 
      { 
        if($currentRotatorIndex == $fItemsCount - 1)
			{
				$currentRotatorIndex = 0;
			}
		else
			{
				$currentRotatorIndex++;
			}
        if($currentRotatorIndex == 0)
          {
            $stopAfterAll++;
          }
        if($stopAfterAll == 1)
          {
            clearInterval($rotator);
          }
      } 
    else if($mode == 'prev') 
      { 
        ($currentRotatorIndex == 0) ? $currentRotatorIndex = ($fItemsCount - 1) : $currentRotatorIndex--; 
      } 
    else if($mode == 'next') 
      { 
        ($currentRotatorIndex == $fItemsCount - 1) ? $currentRotatorIndex = 0: $currentRotatorIndex++; 
      } 
    else if($mode == 'dot') 
      { 
        $currentRotatorIndex = $dotIndex; 
      } 
    
    $j("a.dot.current").removeClass("current"); 
    $j(".feature_nav a.dot:eq(" + $currentRotatorIndex + ")").addClass("current");  

    // rotate f items 
	$scrollTo = $currentRotatorIndex * $fItemWidth * -1;
	$j("#content_col .items").animate({
			left: $scrollTo
		}, 500, function(){
			
			});

  }

if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6) {
  try {
    document.execCommand("BackgroundImageCache", false, true);
  } catch(err) {}
}

$j(window).load(function(){
    // set items height
    var $itemH = -1;
    $j("#content_col .feature_item").each(function(){
        if($j(this).height() > $itemH)
          {
            $itemH = $j(this).height();
          }
      });
    $j("#content_col .feature_box").css("height", $itemH);
  });
