var $j = jQuery.noConflict();

function seoText() {
    if($j("#footer #seotext").length > 0) {
       $j("#footer #seotext").toggle(); 
    }
    if($j("#footer #extra_text").length > 0) {
       $j("#footer #extra_text").toggle(); 
    }
}

function pAnimate(num) {
    var currTxt = ".current-text" + num;
    // $j(currTxt).show();

    $j('#portfolio-ie').html('');
    $j('#portfolio-ie').html($j(currTxt).html());
    $j('.portfolio-content').hide();
}

/**
* Set background position of nav
* This show indicator of position in site
* Pixel Position are very unreliable as each browser is slighty different.
*/
function set_background_pos(pos)
{
	combined_width = 0;
	//get widths of each li
	$j('.menu-primary-menu-container li:visible').each(function(index) {
		if (index==pos-1) return false;
    	$j(this).addClass('dave'+$j(this).outerWidth()+'i'+index);
    	//combined_width .= $j(this).width();
    	combined_width = combined_width + $j(this).outerWidth();
	});
	
	menu_pos = (combined_width+10);
	
	$j(".menu-primary-menu-container").css({backgroundPosition: menu_pos+'px -40px'});
}

$j(document).ready(function() {
    
    if($j('.portfolio-content').is(':visible')) {
        $j('.portfolio-content').hide();
    }
    
    if($j('#portfolio')) {
        $j('#portfolio').show();
        activeItem = $j("#portfolio li:first");
        $j('.portfolio-content').hide();
        pAnimate(1); // see the pAnimate function activated from the portfolio slide
        $j(activeItem).addClass('active');
        $j("#portfolio > li").click(function(){
            $j(activeItem).animate({width: "20px"}, {duration:300, queue:false});
            $j(this).animate({width: "600px"}, {duration:300, queue:false});
            activeItem = this;
        });
    }            
    
    var sm4height = $j('#sm-four').height();
    var thumbheight = $j('#body_content_thumb').height();
    var leftheight = $j('#body_content_left').height() + 80;
        
    if(thumbheight > leftheight) {
        // alert(thumbheight + " : " + leftheight);
        $j('#body_content_thumb').height(leftheight);
    }
    
   // function for menus
  function menuhide() {
      $j(".sub-menu").hide();
      $j("#sm-one").hide();
      $j("#sm-two").hide();
      $j("#sm-three").hide();
      $j("#menu-item-430 ul").hide();
      $j("#menu-item-431 ul").hide();
      $j("#menu-item-531 ul").hide();
      $j(".menu-primary-menu-container").css({backgroundPosition: '10px -50px'});
  }
  
  menuhide();
  subpath = "none";
  menu_pos = 1;
  var pathname = window.location.pathname;
  // alert(pathname);
  
  if(pathname == "/services/web-design/") {
      $j("#menu-item-271").addClass("current_page_item");
  }
  
  if(pathname.lastIndexOf("company") > -1) {
      subpath = "company";
      menu_pos = 6;
  }
  if(pathname.lastIndexOf("sitemap") > -1) {
      subpath = "sitemap";
  }
  if(pathname.lastIndexOf("services") > -1) {
        subpath = "services";
     }
   if(pathname.lastIndexOf("portfolio") > -1) {
        subpath = "portfolio";
        menu_pos = 5;
   }
   if(pathname.lastIndexOf("services") > -1) {
        subpath = "services";
   }
   if(pathname.lastIndexOf("services") > -1 && pathname.lastIndexOf("web-design") > -1) {
        subpath = "website-services";
        menu_pos = 2;
   }
   if(pathname.lastIndexOf("services") > -1 && pathname.lastIndexOf("marketing") > -1) {
        subpath = "marketing-services";
        menu_pos = 4;
   }
   if(pathname.lastIndexOf("services") > -1 && pathname.lastIndexOf("graphic-design") > -1) {
        subpath = "graphic-services";
        menu_pos = 3;
   }
   
   set_background_pos(menu_pos);
   
   if(subpath != "none") {
      switch(subpath) {
          case "website-services":
          $j("#menu-item-430 ul").show();
          $j("#sm-one").show();
          //$j(".menu-primary-menu-container").css({backgroundPosition: '60px -40px'});
          $j(".menu-item-430").css({fontWeight:'bold'});
          $j(".menu-item-577").css({fontWeight:'bold'});
          break;
          case "marketing-services":
          $j("#menu-item-430 ul").show();
          $j("#sm-two").show();
          //$j(".menu-primary-menu-container").css({backgroundPosition: '240px -40px'}); 
          break;
          case "graphic-services":
          $j("#menu-item-430 ul").show();
          $j("#sm-three").show();
          //$j(".menu-primary-menu-container").css({backgroundPosition: '140px -40px'}); 
          break;
          case "company":
          $j("#menu-item-431 ul").show();
          //$j(".menu-primary-menu-container").css({backgroundPosition: '372px -40px'}); 
          break;
          case "services":
          $j("#menu-item-430 ul").show();
          //$j(".menu-primary-menu-container").css({backgroundPosition: '60px -40px'}); 
          break;
          case "portfolio":
          $j('#menu-item-531 ul').show();
          //$j(".menu-primary-menu-container").css({backgroundPosition: '310px -40px'});
          break;
          case "sitemap":
          $j('#body_content_left ul').css({ listStyleType: 'none' });
          break;
      }
   } else {
       $j(".menu-primary-menu-container").css({backgroundPosition: '10px -40px'}) 
   }
   
   // for rhs menu

   // Check if the third level navigation is selected
 
    if($j("#menu-marketing-menu").is(":visible") || $j("#menu-web-menu").is(":visible") || $j("#menu-graphic-menu").is(":visible")) {
        var nsh = 0;
        if($j("#menu-marketing-menu").is(":visible")) {
            var nav_side = $j("#menu-marketing-menu");
            nsh = $j("#menu-marketing-menu").height();
        }
        if($j("#menu-web-menu").is(":visible")) {
            var nav_side = $j("#menu-web-menu");
            nsh = $j("#menu-web-menu").height();
        }
        if($j("#menu-graphic-menu").is(":visible")) {
            var nav_side = $j("#menu-graphic-menu");
            nsh = $j("#menu-graphic-menu").height(); 
        }
        
        $j('#body_content_thumb .current_page_item').prevAll("li").addClass('nav_border');
        $j('<div id="nav3_spacer"></div>').prependTo($j("#body_content_thumb")); 
        
        var sm4h = 87 + nsh + "px";
        // $j("#sm-four").css({marginTop:sm4h}).show();
        $j("#sm-four").show();
    }
   
    if($j("#bottom-details")) {
        $j("#bottom-details li:last").prevAll("li").addClass('bottom-border');
    }
});
