 jQuery.noConflict();
 jQuery(document).ready(function()
		{
			updateHeight();
			//show links to members only area if logged in
			var dashValue = jQuery.cookie("DASHBOARD");
			if (dashValue == '1') {
				jQuery("#content_top_nav a").show();
			}
			
			reinitialiseScrollPane = function()
				{	
					rewritePath();
				}
			
			//rewrite relative links after the page has been laoded into the portlet
			function rewritePath()
			{				
				jQuery("#inline_frame img.discount_page_logo").each(				
					function(i){
						var nsattr = jQuery(this).attr("src");	
						
						if(nsattr != null){
							if(nsattr.substring(0,3) == "../"){
								jQuery(this).attr("src", nsattr.substring(3));
							}
							else{
								jQuery(this).attr("src", getPath(nsattr));
							}
							((jQuery(this).width() > 200)? jQuery(this).width(200): null);
						}						
					});	
					//remove discount code if not logged in
					var dashValue = jQuery.cookie("DASHBOARD");
					if (dashValue != '1') {
						jQuery("#inline_frame #discount-code").empty();
						jQuery("#inline_frame #discount-code").append('<b>To Use This Discount:</b> <a href="https://be.freelancersunion.org/s/index.php/user/login/">Sign in</a> or  <a href="https://be.freelancersunion.org/f/register/action/emailReg">join now</a>.');
					}
					
					setTimeout(function(){
						jQuery("#inline_frame img.discount_page_logo").each(
							function(i){
								((jQuery(this).width() > 200)? jQuery(this).width(200): null);
								
							}
						);
						jQuery('#inline_frame').jScrollPane({showArrows:true});
					},1000);
				// this initialises the demo scollpanes on the page.
				jQuery('#inline_frame').jScrollPane({showArrows:true});
			}

			function getPath(opath){
				var Apath;
				if(opath.charAt(0) != '/'){
					Apath = opath.substring(opath.indexOf(location.host)+(location.host).length);
				}
				else{
					Apath = opath;
					}
				var Wpath = location.pathname;
				var newPathname = "";
				var nDir;
				var index;
				for ( i = 0; i < Apath.length; i++ ) {
					if(Wpath.charAt(i) == Apath.charAt(i)){
						newPathname += Apath.charAt(i);
						index = i;
					}
					else{
						break;
					}
				}
				nDir = Wpath.substring(index+1).split("/");
				
				if(opath.charAt(0) != '/'){
					newPathname += nDir[0] + "/" + Apath.substring(index+1);
				}
				else{
					newPathname += nDir[0] + "/" + nDir[1] + "/" + Apath.substring(index+1);
					}
				return newPathname;
			}
			
			function updateHeight(){
				jQuery("#vendor .nav_cont").css({ height: "auto"});
				jQuery("#category .nav_cont").css({ height: "auto"});
				
				var vheight = jQuery("#vendor").height();
				var cheight = jQuery("#category").height();
				var topheight = jQuery(".top_info").height();
				
				if(vheight < cheight){
					var nheight = cheight - topheight;
					jQuery("#vendor .nav_cont").css({ height:nheight, minHeight:nheight });
					jQuery("#category .nav_cont").css({ height:nheight, minHeight:nheight });
				}
				else if(cheight < vheight){
					var nheight = vheight - topheight;
					jQuery("#vendor .nav_cont").css({ height:nheight, minHeight:nheight });
					jQuery("#category .nav_cont").css({ height:nheight, minHeight:nheight });
					
				}			
			}
			
			//attach functions to the click event for each category
			jQuery('#nav_categ .inline_nav').bind(
				'click',
				function() {
				jQuery('div.inline_nav , div.inline_nav_current')
				.addClass('inline_nav')
				.removeClass('inline_nav_current');
				jQuery('.cur_icon').hide();
				jQuery(this).addClass('inline_nav_current');
				var title = jQuery(this).attr("title");
				jQuery("#vendor div[class^='nav_']").hide(); 
				jQuery("#vendor #nav_"+title).show(); 
				jQuery(this).find('.cur_icon').show(); 
				jQuery('#inline_frame').empty().jScrollPane();
				//set the hieght of the div based on the text content, also set margins fod the icons and arrow image	- Category Pane
				var nheight = jQuery(this).find('.f_left').height() + 19;
				jQuery(this).height(nheight);
				var iconM = (nheight - jQuery(this).find('.comp_icon').height())/2;
				((iconM > 0) ? (jQuery(this).find('.comp_icon').css('marginTop',Math.round(iconM))) : null);
				var arrowM = (nheight - jQuery(this).find('.cur_icon').height())/2;
				((arrowM > 0) ? (jQuery(this).find('.cur_icon').css('marginTop',Math.round(arrowM))) : null );
				
				//set the hieght of the div based on the text content, also set margins fod the icons and arrow image	- Vendor Pane
				jQuery("#vendor #nav_"+title+" div.inline_nav").each(
					function(i){
					var nheight = jQuery(this).find('.f_left').height() + 19;
					jQuery(this).height(nheight);
					var iconM = (nheight - jQuery(this).find('.comp_icon').height())/2;
					((iconM > 0) ? (jQuery(this).find('.comp_icon').css('marginTop',Math.round(iconM))) : null);
					var arrowM = (nheight - jQuery(this).find('.cur_icon').height())/2;
					((arrowM > 0) ? (jQuery(this).find('.cur_icon').css('marginTop',Math.round(arrowM))) : null );
					
					
				});
				updateHeight();
				//jQuery("#nav_categ").jScrollPane({showArrows:true});
				//jQuery("#vendor div[class^='nav_']").jScrollPane({showArrows:true});
		    });
			
			//attach functions to the click event for each vendor and load the page into the detail portlet using the link specified  in a.address
			jQuery("#vendor div[class^='nav_'] .inline_nav").bind(
				'click',
				function() {
				var parent = (this).parentNode.id;
				jQuery('#'+parent+' div.inline_nav,'+'#'+parent+' div.inline_nav_current')
				.addClass('inline_nav')
				.removeClass('inline_nav_current');
				jQuery('#vendor .inline_nav .cur_icon').hide();
				jQuery(this).addClass('inline_nav_current');
				jQuery(this).find('.cur_icon').show(); 
				var link = jQuery(this).find('.address').attr("href");
				jQuery("#inline_frame").load(link+" #content", '', reinitialiseScrollPane);	
				updateHeight();
		    });
			
	
			//stimulate cllicks
			setTimeout(function(){
			jQuery('#nav_categ .inline_nav:first').click();
			jQuery("#vendor div[class^='nav_'] .inline_nav:first").click();
			},1000);
			
			
			//jQuery("#vendor div[class^='nav_'] .inline_nav:first").click();
		}
		
	);

