// TOP NAVIGATION
mainNav = function() {
	$("#topnav li").bind("mouseenter",function(){
                this.className += "_over over";
	}).bind("mouseleave",function(){
                this.className = this.className.replace("_over over", "");
	});
}




// FILTER
$(document).ready(function() {
	$('ul#filter a').click(function() {
		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');
		
		var filterVal = $(this).text().toLowerCase().replace(' ','-');
				
		if(filterVal == 'all') {
			$('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			
			$('ul#portfolio li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		
		return false;
	});
});

// CAROUSEL
$(function() {
	$(".anyClass").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
   visible: 1
	
	});
});

// IMAGE SLIDER 
$(window).bind("load", function() { 
    $("div#feature1").slideView() 
});

$(window).bind("load", function() { 
    $("div#feature2").slideView() 
});

$(window).bind("load", function() { 
    $("div#feature3").slideView() 
});

// EXTERNAL LINK
window.onload = function() {
  el = document.getElementsByTagName("a");
  for (var i=0; i<el.length; i++){
    if (el[i].rel=="external") {
      el[i].onclick = function () {
        return !window.open(this.href);
      }
    }
  }
}

// CYCLE
$(document).ready(function(){
	
	function onAfter() { 
		$('#slideCaption').html("") 
			.append(this.alt);  
	}
	
	function onAfter() { 
		$('#slideCaption2').html("") 
			.append(this.alt);  
	}

	$('#slideshow') 
	.after('<div id="slideshow-nav">') 
	.cycle({ 
		fx:     'fade', 
		speed:  '4000', 
		timeout: 5000, 
		pager:  '#slideshow-nav',
		pause:   1,
		after: onAfter
	});
	
	$('#slideshow2') 
	.after('<div id="slideshow-nav2">') 
	.cycle({ 
		fx:     'fade', 
		speed:  '4000', 
		timeout: 5000, 
		pager:  '#slideshow-nav2',
		pause:   1,
		after: onAfter
	});
   
});


// SLIDE ANCHOR
$(document).ready(function() {
 function filterPath(string) {
    return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
 }
$('a[href*=#]').each(function() {
	if ( filterPath(location.pathname) == filterPath(this.pathname) && location.hostname == this.hostname && this.hash.replace(/#/,'') ) {
		var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
		var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($target) {
				var targetOffset = $target.offset().top;
					$(this).click(function() {
				    $('html, body').animate({scrollTop: targetOffset}, 1200);
					return false;
					});
				}
			}
		});
	});
