//Main Menu dropdown
$(function(){
 
	//Hide SubLevel Menus
	$('#main_menu ul li ul').hide();
 
 	//Original height of #main_header
 	var main_menu_height = $('#main_header').height();
 
	//OnHover Show SubLevel Menus
	$('#main_menu div ul li').not($('#main_menu ul li ul li')).hover(
		
		//OnHover
		function(){
		
			//Hide Other Menus
			$('#main_menu ul li').not($('ul', this)).stop();
			
			//Calc height of sub menu
			var this_menu = $('ul', this);
			var this_menu_has_how_many_lis = $('ul li', this).length;
			var height_to_add = this_menu_has_how_many_lis * 35;
			
			$('#main_header').animate({
				height: '+='+height_to_add
			}, 200, function(){
				var new_height = $(this).height();

				this_menu.stop(true, true).fadeIn('fast');
			});
 
		},
		//OnOut
		function(){

			var this_menu = $('ul', this);
			
			this_menu.stop(true, true).fadeOut('fast');
			
			$('#main_header').animate({
				height: main_menu_height
			}, 200, function(){
			
			});
		
		}
	);
 
});

//Home Page default nive slider
//$(window).load(function() {
//    $('#slider').nivoSlider();
//});

//Home Page blog posts
$(window).load(function() {
    $('.blog_home_slider').nivoSlider({manualAdvance: true, effect: 'fade'});
});

//Single Portfolio Main
$(window).load(function() {
    $('#single_portfolio_slider').nivoSlider({pauseTime: 5000});
});

//Home page clients slider
$('#clients').anythingSlider({
	showMultiple : 3,
	changeBy     : 1,
	startStopped : true,
	delay : 9000,
	appendControlsTo: '#clients_controls',
	onInitialized: function(e, slider) {
        slider.$controls
            .prepend('<ul id="prev_client"><li><a class="prev_client"></a></li></ul>')
            .append('<ul id="next_client"><li><a class="next_client"></a></li></ul>')
            .find('.prev_client, .next_client').click(function(){
                if ($(this).is('.prev_client')) {
                    slider.goBack();
                } else {
                    slider.goForward();
                }
            });
    }
});

function clearText(field){
	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;
	
}

$('a img.size-medium, a img.size-small, a img.size-thumbnail, a img.size-full, a img.size-large, a img.topup').parent().attr("rel","colorbox");

$(document).ready(function(){
	$('a[rel="colorbox"]').colorbox();
	
	/*$.featureList(
		$('#slider .nav_img > a '),
		$('#slider > div.slide-item'),
		{
		start_item : 0,
		transition_interval : 5000,
		transition_speed : 300,
		nav_prev: $('#slider .nivo-prevNav'),
		nav_next: $('#slider .nivo-nextNav')
		}
	);*/
	$('#slider').slides({
		preload: true,
		preloadImage: 'img/loading.gif',
		play: 5000,
		pause: 2500,
		hoverPause: true,
		animationStart: function(current){
			$('.slide_content').animate({
				bottom:-35
			},100);
			if (window.console && console.log) {
				// example return of current slide number
				console.log('animationStart on slide: ', current);
			};
		},
		animationComplete: function(current){
			$('.slide_content').animate({
				bottom:0
			},200);
			if (window.console && console.log) {
				// example return of current slide number
				console.log('animationComplete on slide: ', current);
			};
		},
		slidesLoaded: function() {
			$('.slide_content').animate({
				bottom:0
			},200);
		}
	});
	$(".flickr_widget a").attr("target","_blank");
	$(".flickr-thumb a").attr("target","_blank");
	
	$(".team_hentry").each(function(){
		var hentry = $(this);
		hentry.delegate('.img-item', 'mouseover',  function(){
			$(".team_img .img-item", hentry).animate({opacity: "hide"}, 500);
			$(".team_text .team_content", hentry).animate({opacity: "hide"}, 0);
			$(".team_img .img-item_sm", hentry).animate({opacity: "show"}, 500);
			$(".team_text .team_content_sm", hentry).animate({opacity: "show"}, 0);
		}).delegate('.img-item_sm', 'mouseout',  function(){
			$(".team_img .img-item_sm", hentry).animate({opacity: "hide"}, 500);
			$(".team_text .team_content_sm", hentry).animate({opacity: "hide"}, 0);
			$(".team_img .img-item", hentry).animate({opacity: "show"}, 500);
			$(".team_text .team_content", hentry).animate({opacity: "show"}, 0);
		});
	});
	
});

