var id_part = '';

$(document).ready(function() {
 
 
 
 positionLeftNav('menu-categories-list',100);
 positionLeftNav('menu-categories-list2',88);

 if($('div #products_area').length > 0)
 {
  attachLeftNavLinks('menu-categories-list');
  attachPaginationLinks('menu-categories-list');
 }
 
 $(window).resize(function() {
  positionLeftNav('menu-categories-list',100);
  positionLeftNav('menu-categories-list2',88);
 });

 if($('div #products_area').length > 0)
 {
     var href = window.location.href;
     var url_parts = href.split('?');
	 var param_part = url_parts[1];
	 var param_parts = param_part.split('&');
		if (param_parts[0].length > 0) {
			var id_parts = param_parts[0].split('=');;
			id_part = id_parts[1];
			if (id_part.length > 0) {
				selectCategories(id_part);
			}
		}
	  positionLeftNav('menu-categories-list',100);
	  positionLeftNav('menu-categories-list2',88);
}
		
});

positionLeftNav = function(className,top)
{
 if(0!=$(".line2:first").innerWidth() && 0!=$('.' + className + ':first').innerWidth())
 {
  $('.' + className + ':first').css({
      left: function(index, value) {
         return parseFloat(($(document).width() - $(".line2:first").innerWidth())/2 + 2);
      }, 
      top: function(index, value) {
        return parseFloat(top);
      }
    });
 } // end if(0!=$(".line2:first").innerWidth() && 0!=$(".menu-categories-list:first").innerWidth())
 
}

/**
Left Nav links
*/
attachLeftNavLinks = function(className)
{
 if(0!=$(".line2:first").innerWidth() && 0!=$('.' + className +':first').innerWidth())
 {
  replaceNavLinks('.' + className +' a.left_nav_link');
  replaceNavLinks('.' + className +' a.left_nav_link_sel');
 } // end if(0!=$(".line2:first").innerWidth() && 0!=$(".menu-categories-list:first").innerWidth())  
}

/**
Pagination links
*/
attachPaginationLinks = function(className)
{
 if(0!=$(".line2:first").innerWidth() && 0!=$('.' + className + ':first').innerWidth())
 {
  replaceNavLinks(".nav-pages a");
 } // end if(0!=$(".line2:first").innerWidth() && 0!=$(".menu-categories-list:first").innerWidth())  
}


/**
hyperlinks - selector selecting hyperlinks
*/
replaceNavLinks = function(hyperlinks)
{
 
 $(hyperlinks).each(function(index) {
  
  var str = $(this).attr('class');
  //alert(str);
  var attach = 0;
  if(typeof str != "undefined" && str.indexOf("no_ajax")!=-1)
  {
   attach = 0;
  }

  if(attach) // class no_ajax does not exists among the classes in the anckor 
  {
   $(this).click(function(event) {
    event.preventDefault();
    // check if the class of the clicked link is left_nav_link or left_nav_link_sel
    var str = $(this).attr('class');
    if(typeof str != "undefined" && str.indexOf("left_nav_link")!=-1)
    {
     var id = $(this).attr('id');
     selectCategories(id); // mark this category and categories right above it as selected
    }
    var href = $(this).attr('href');
    var url_parts = href.split('?');
	var href1 = url_parts[0] + '?' + 'id=' + id + '&' + url_parts[1];
	var purl_parts = 'id=' + id + '&' + url_parts[1];
    var ajax_url = 'products_area.php?' + purl_parts;
    $.ajax({
     url: ajax_url,
     success: function(data) {
      $('div #products_area').html(data);
      attachPaginationLinks();
      positionLeftNav();
	  window.location.href=href1;
     }
    }); // end $.ajax({
   }); // $(this).click(function(event) {
  }
 }); // end .each(function(index) {
 
} // end replaceNavLinks()

// id - id of the left navigation link which was clicked
selectCategories = function(id) {
 
 var str = id.substr(6);
 var a = str.split('_');
 
 // Left Navigation
 $("a.left_nav_link_sel").removeClass('left_nav_link_sel').addClass('left_nav_link');
 var n_id = 'nlink';
 for(var i=0; i<a.length; ++i)
 {
  n_id += '_' + a[i];
  $('a#' + n_id).removeClass('left_nav_link').addClass('left_nav_link_sel');
 }

 // Top Navigation
 var t_id = 'tlink';
 t_id += '_' + a[0];
 $(".line2 img.no_rollover").each(function(index) {
  $(this).attr('src',$(this).attr('src').replace('_sel',''));
 });
 $(".line2 img.no_rollover").removeClass('no_rollover');
 
 //$('.line2 #' + t_id).addClass('no_rollover');
 //$('.line2 #' + t_id).attr('src',$('.line2 #' + t_id).attr('src').replace('.jpg','_sel.jpg')); 

} // end function selectCategories()


$(document).ready(
function()
{
	url = 'http://www.honeyintherough.com/';
	
	$('div#item2').html('<img title="CLOTHING" id="tlink_103" style="left:96%; position:relative; z-index:5000; cursor:pointer;" onmouseover=new_img("cloth_ro.png",this.id); onmouseout=new_img("cloth.png",this.id); onclick=javasvript:window.location="'+url+'clothing/"; src="/skin1/images/navigation/cloth.png">');
	
	$('div#item3').html('<img title="JEWELRY" id="tlink_281" style="left:169%; position:relative; cursor:pointer;" onmouseover=new_img("jewel_ro.png",this.id); onmouseout=new_img("jewel.png",this.id); onclick=javasvript:window.location="'+url+'jewelry/"; src="/skin1/images/navigation/jewel.png">');
	
	$('div#item4').html('<img style="position:relative; left:23%; z-index:5000; cursor:pointer;" id="access_img" src="/skin1/images/navigation/access.png" title="ACCESORIES" onmouseover=new_img("access_ro.png",this.id); onclick=javasvript:window.location="'+url+'accessory/"; onmouseout=new_img("access.png",this.id);>');
	
	//j = $('img#tlink_103').closest('a').attr('href');
	//$('div#item3').html('<img id="tlink_103" style="left:96%; position:relative;" onmouseover=new_img("cloth_ro.png",this.id); onmouseout=new_img("cloth.png",this.id); onclick=javasvript:window.location="'+j+'"; src="/skin1/images/navigation/cloth.png">');
	//<a class="menu_item_white" href="http://www.honeyintherough.com/new-arrivals/" title="NEW ARRIVALS"><img id="tlink_103" style="left:96%; position:relative;" onmouseover="new_img('cloth_ro.png',this.id)" onmouseout="new_img('cloth.png',this.id);" src="/skin1/images/navigation/cloth.png"></a>
	
	//k = $('img#tlink_281').closest('a').attr('href');
	//$('div#item3').html('<img id="tlink_281" style="left:169%; position:relative; cursor:pointer;" onmouseover=new_img("jewel_ro.png",this.id); onmouseout=new_img("jewel.png",this.id); onclick=javasvript:window.location="'+k+'"; src="/skin1/images/navigation/jewel.png">');
	//alert('hello');
	/*d = $(".price-value").html();
	get = d.split('$');
	get_more = get[1].split('.');
	
	discount_price = get_more[0];
	
	c = $(".market-price-value").html();
	
	more = c.split('$');
	more_more = more[1].split('.');
	
	orignal_price = more_more[0];
	
	if(orignal_price!="")
	{
		$('.market-price').html('');
		$('.market-price').prev('div.price-row').hide();
		
		$('.market-price').html('forn color="#FE2C02">$'+discount_price+'</font>&nbsp;&nbsp;<span style="color:#172448"><del>$'+orignal_price+'</del></span>');
		alert('hello');
	}*/
});
