(function($){

	$.fn.navHilight = function(opts){

		var def = {},

			opts = $.extend(def, opts);

		

		return this.each(function(){

			var $nav=$(this),

				$item = $nav.find('li');

			

			$item.each(function(){

				var $item = $(this).children('a');

				var $i = $(this).children('a').children('img').bind({

					dragstart: function(e){

						e.preventDefault();

					}

				});

				var url = $i.attr('src').replace(/.png/, '_on.png'),

					onState = new Image();

				onState.src = url;

				$(onState).css({

					position: 'absolute',

					top: 0,

					left: 0,

					zIndex: 1,

					opacity: 0

				}).bind({

					dragstart: function(e){

						e.preventDefault();	

					}

				}).appendTo($item);

				

				if($(this).hasClass('active')){

					$i.attr('src', onState.src);

				}

				

				$item.bind({

					mouseenter: function(e){

						if( $(this).parent('li').hasClass('active') ) return false;

						$(onState).css({

							opacity: 1

						});

						$i.css({

							opacity: 0

						});

					},

					mouseleave: function(e){

						if( $(this).parent('li').hasClass('active') ) return false;

						$(onState).css({

							opacity: 0

						});

						$i.css({

							opacity: 1

						});

					}

				});

			});

		});

	}

	

	$.fn.logo = function(){

		return this.each(function(){

			$obj = $(this);

			$nav = $('#subnav li').eq( $obj.index() ).css('cursor', 'pointer').bind({

				mouseenter:function(e){

					$('.logos').eq($(this).index()).stop().animate({

						opacity: 1

					}).siblings().not('.sticky').stop().animate({

						opacity: .25

					});

					$(this).addClass('active');

				},

				mouseleave:function(e){

					if( $('.logos').eq($(this).index()).hasClass('sticky') ) return false;

					$('.logos').eq($(this).index()).stop().animate({

						opacity: .25

					});

					$(this).removeClass('active');

				},

				click: function(e){

					$('.logos').eq($(this).index()).addClass('sticky').siblings().removeClass('sticky').animate({

						opacity: .25

					});

					$(this).siblings().removeClass('active');

				}

			});

			$obj.css({

				opacity: .25,

				cursor: 'pointer'

			}).bind({

				mouseenter:function(e){

					$(this).stop().animate({

						opacity: 1

					}).siblings().not('.sticky').stop().animate({

						opacity: .25

					});

					$('#subnav>li').eq($(this).index()).addClass('active');

				},

				mouseleave:function(e){

					if( $(this).hasClass('sticky') ) return false; 

					$(this).stop().animate({

						opacity: .25

					});

					$('#subnav>li').eq($(this).index()).removeClass('active');

				},

				click: function(e){

					$(this).addClass('sticky').siblings().removeClass('sticky').animate({

						opacity: .25

					});

					$('#subnav>li').eq($(this).index()).siblings().removeClass('active');

				}

			});



		});

	}



	$.fn.services = function(){

		return this.each(function(){

			$obj = $(this);

			$items = $obj.find('li');
			
			$items.eq(0).addClass('active');
			
			$contents = $('#services_content > li');

			$items.bind({

				mouseenter: function(e){

					id = $(this).index();

					$contents.hide();

					$contents.eq(id).show();
					
					$(this).addClass('active').siblings().removeClass('active');

				},
				mouseleave: function(e){
					
				}

			});

		});

	}



})(jQuery);



$(function(){

	$('#nav').navHilight();

	if( $('.logos').length>0 ){

		$('.logos').logo();

		$('.logos').eq(0).mouseover().click();

	}

	if( $('#creative_services li').length>0 ) $("#creative_services").services();
	
});
