/* Script for logo hover */
$(function(){
	$('#business-logos a').each(function(){
		switch($(this).attr('id'))
		{
			case 'bbb':
				$(this).hover(
					function(){
						$(this).children('img').attr({src:'/Images/Home/better-business-logo-hover.png'});
					},
					function(){
						$(this).children('img').attr({src:'/Images/Home/better-business-logo.png'});
					}
				);
				break;
			case 'la-chamber2':
				$(this).hover(
					function(){
						$(this).children('img').attr({src:'/Images/Home/la-chamber-of-commerce-logo-hover.png'});
					},
					function(){
						$(this).children('img').attr({src:'/Images/Home/la-chamber-of-commerce-logo.png'});
					}
				);	
				break;
			case 'nawbo':
				$(this).hover(
					function(){
						$(this).children('img').attr({src:'/Images/Home/nawbo-logo-hover.png'});
					},
					function(){
						$(this).children('img').attr({src:'/Images/Home/nawbo-logo.png'});
					}
				);
				break;
				case 'nwboc':
				$(this).hover(
					function(){
						$(this).children('img').attr({src:'/Images/Home/nwboc-hover.png'});
					},
					function(){
						$(this).children('img').attr({src:'/Images/Home/nwboc.png'});
					}
				);
				break;
		}
	});
});

$(function(){
if ($(window).height() > 768){
$('.container-trans:last').height($(window).height()-630);
}
	var location_hash = (window.location.hash !== '') ? window.location.hash : "#home";
	var curr_section = $('ul#menu li a[href="'+location_hash+'"]').toggleClass('current');
	$.localScroll.hash({

    onBefore: function(e,target,element)
    {
        curr_section.toggleClass('current');
        curr_section = $('ul#menu li a[href="'+window.location.hash+'"]').toggleClass('current');
    }	
});
	$('ul#menu li a').click( function(){
		
		if(curr_section != "")
		{
			curr_section.toggleClass('current');
		}
		$(this).toggleClass('current');
		curr_section = $(this);
		
	});
	$('ul#menu').localScroll({
		hash:true
	});
});
$(function()
{
	var carsousel = $('ul#carousel-items');
	var carousel_width = carsousel.outerWidth();
	var carsouel_items = carsousel.children();
	var max_display_items = 5;
	var carsouel_items_width = carsouel_items.filter(':first').width();
	var items_pad = (carousel_width - carsouel_items_width* max_display_items) / (max_display_items+1);
	var first_item = carsouel_items.filter(':first');
	var last_item = carsouel_items.filter(':last');
	var first_item_pos = "";
	var last_item_pos = "";
	
	carsouel_items.each(function(){
		var num_prev = $(this).prevAll().length;
		$(this).css({
			'position':'absolute',
			'margin':0,
			'top':0,
			'left': (num_prev * carsouel_items_width) + ((num_prev+1) * items_pad)
		});
		$(this).children('a').css("opacity",.6).hover(function(){
			$(this).animate({'opacity':1},750);
		},
		function(){
			$(this).animate({'opacity':.6},750);
		});
	});
	
	first_item_pos = first_item.position();
	last_item_pos = last_item.position();
	if (first_item_pos.left >= (items_pad))
	{
		$('#carousel #right-pointer').css("visibility","hidden");
	}
	
	$('#carousel div.carousel-pointer').click(function(){
		if($(this).is('#left-pointer'))
		{
			carouselMove('left');
		}
		else{
			carouselMove('right');
		}
	});
	
	
	function carouselMove(direction)
	{
		move_amount = (direction == "left") ? -(items_pad + carsouel_items_width) :(items_pad + carsouel_items_width);
		
		carsouel_items.each(function(){
			var curr_position = $(this).position();
			$(this).css("left",curr_position.left + move_amount + "px");
		});
		first_item_pos = first_item.position();
		last_item_pos = last_item.position();
		if (first_item_pos.left >= (items_pad))
		{
			$('#carousel #right-pointer').css("visibility","hidden");
		}
		else
		{
			$('#carousel #right-pointer').css("visibility","visible");
		}
		
		if (last_item_pos.left <= (carousel_width - items_pad))
		{
			$('#carousel #left-pointer').css("visibility","hidden");
		}
		else
		{
			$('#carousel #left-pointer').css("visibility","visible");
		}
	
	}
});
