﻿$(function(){

	$('.family_a').bind( 'click', getFamily );

	$('.product_a').bind( 'click', getProduct );
	
	$(".outline .root1 li").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");});
 	
	$(".outline .root1 strong:even").addClass("zebra");
	$(".productChild li:odd").addClass("odd");
	$(".productChild li:even").addClass("even");
	//pid = $.cookie('pid');
	//fid = $.cookie('fid');

/*	if( fid != null ){
		$("a.family_a[fid='"+fid+"']").trigger('click')
		if( pid != '') $("a.product_a[pid='"+pid+"']").trigger('click') 
	} else {*/
		$('.family_a:first').trigger('click')
	//}

});

var getFamily = function(e){

	 itsMe = $(this).hasClass('expanded');
	 if(!itsMe) $('.expanded').removeClass('expanded').siblings('.productChild').slideUp();
	 $(this).toggleClass('expanded').parent('.root1').find('.productChild').slideToggle();
	 $('.clicked').removeClass('clicked');
	 
	 $(this).addClass('clicked').addClass('expanded');
	 getDetailsFamily($(this).attr('FID'))
	 //$.cookie('fid', $(this).attr('FID'));
	 //$.cookie('pid', null);

	 return false;
}

var getProduct = function(e){
	$('.clicked').removeClass('clicked');
	$(this).addClass('clicked');
	getDetails($(this).attr('FID') ,$(this).attr('PID'));	
	//$.cookie('pid', $(this).attr('PID'));
	//$.cookie('fid', $(this).attr('FID'));

	return false;
}

function getDetails( fID, pID ){
	$('#loadBuffer').load('/sgi/load_detail.aspx', { FID: fID, PID: pID, sURL: window.location}, refreshData );
	return false;
}

function getDetailsFamily( fID){
	$('#loadBuffer').load('/sgi/load_detail_family.aspx', { FID: fID, sURL: window.location}, refreshData );
	return false;
}

var refreshData = function(){

	$(document).ready( function(){
			var a = new Array();

			$(".detailIndustry").add(".detailIndustry ul li").each(function(x){
					test = false;
					b = a[x] = $(this).html();
					for (i=0;i<a.length-1;i++){
							if (b ==a[i]) test =true;
					}
					if (test) $(this).remove();
			})
	}); 

	$('#CollapsiblePanel1 .CollapsiblePanelContent').html( $('.detailDescription').html() ).css('height', '250');
	$('#CollapsiblePanel2 .CollapsiblePanelContent').html( $('.detailIndustry').html() ).css('height', 'auto');
}
 
