// JavaScript Document 

jQuery(document).ready(function($) {
	
	$(".toggle").hide();
	$(".trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("100");
	});
	
	
	$('.circle').mosaic({
		opacity		:	0.8			//Opacity for overlay (0-1)
	});
	
	$('.fade').mosaic();
	
	$('.bar').mosaic({
		animation	:	'slide'		//fade or slide
	});
	
	$('.bar2').mosaic({
		animation	:	'slide'		//fade or slide
	});
	
	$('.bar3').mosaic({
		animation	:	'slide',	//fade or slide
		anchor_y	:	'top'		//Vertical anchor position
	});
	
	$('.cover').mosaic({
		animation	:	'slide',	//fade or slide
		hover_x		:	'400px'		//Horizontal position on hover
	});
	
	$('.cover2').mosaic({
		animation	:	'slide',	//fade or slide
		anchor_y	:	'top',		//Vertical anchor position
		hover_y		:	'80px'		//Vertical position on hover
	});
	
	$('.cover3').mosaic({
		animation	:	'slide',	//fade or slide
		hover_x		:	'400px',	//Horizontal position on hover
		hover_y		:	'300px'		//Vertical position on hover
	});
	
	
	
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	
	
	//Default Action
	$(".minitab_content").hide(); //Hide all content
	$("ul.minitabs li:first").addClass("active").show(); //Activate first tab
	$(".minitab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.minitabs li").click(function() {
		$("ul.minitabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".minitab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	
	
	$('.project').mouseenter(function(e) {
        $(this).children('a').children('span').fadeIn(200);
    }).mouseleave(function(e) {
        $(this).children('a').children('span').fadeOut(200);
    });
	
	
	
	
	$(".accordion").accordion();
	
	
	
	//usage w/ smoothscroll
	//set the link
	$('#top-link').topLink({
		min: 400,
		fadeSpeed: 500
	});
	//smoothscroll
	$('#top-link').click(function(e) {
		e.preventDefault();
		$.scrollTo(0,300);
	});
	
	
	/**SWITCHER **/
	function switcher_cookie(){
		layout = '';
		if($('#root').hasClass('wide'))
			layout = 'wide';
		else
			layout = 'narrow';
		bg = $('select#switcher_bg').val();
		cufon = $('#switcher_cufon').val();
		color = $('#color1').val();
		$.cookie('airborn_switcher', 'layout=' + layout + '|bg=' + bg + '|cufon=' + cufon + '|color=' + color, { path: '/' });
	}
	
	if ($('#switcher').length) {
		if($('#root').hasClass('wide'))
			$('#wideView').addClass('white');
		else
			$('#narrowView').addClass('white');
			
		if($('select#switcher_bg').val() != 'color')
			$('#pick-me-a-color').hide();
		
		$('#wideView').click(function(event){
			event.preventDefault();
			$('#wideView').addClass('white');
			$('#narrowView').removeClass('white');
			$('#root').addClass('wide');
			switcher_cookie();
		});
		$('#narrowView').click(function(event){
			event.preventDefault();
			$('#narrowView').addClass('white');
			$('#wideView').removeClass('white');
			$('#root').removeClass('wide');
			switcher_cookie();
		});
		$('#switchRight a').click(function(event){
			event.preventDefault();
			$('#switchLeft').slideToggle(200);
		});
		$('select#switcher_bg').change(function(){
			val = $(this).val();
//			if( val == 'def' )
//				return;
			if( val == 'color'){
				$('#pick-me-a-color').show();
				if($('#root').hasClass('wide'))
					$('#header').css('background', $('#color1').val());
				else
					$('body').css('background', $('#color1').val());
			}
			else{
				$('#pick-me-a-color').hide();
				if($('#root').hasClass('wide'))
					$('#header').css('background', 'url(' + val + ')' );
				else
					$('body').css('background', 'url(' + val + ')' );
			}
			switcher_cookie();
		});
		$('#color1').change(function(){
			val = $('select#switcher_bg').val();
			if( val == 'color'){
				if($('#root').hasClass('wide'))
					$('#header').css('background', $(this).val());
				else
					$('body').css('background', $(this).val());
			}
			switcher_cookie();
		});
		$('#switcher_cufon').change(function(){
//			val = $('select#switcher_cufon').val();
//			if( val == 'def' )
//				return;
			switcher_cookie();
			window.location.reload();
//			Cufon.replace('h1, h2, h3, h4, h5, h6, .mm', { hover: true, hoverables : {span: true},  fontFamily: val });
		});
	}
	/** COMMENT LINKS **/
	if ($('.comment-reply-link').length) {
		$('.comment-reply-link').addClass('button thin1 white').wrapInner('<span />');
	}
	/** COMMENT TITLE **/
	if ($('#reply-title').length) {
		temp = $('#reply-title').html();
		$('#reply-title').replaceWith('<h4 class="title grey" id="reply-title">' + temp + '</h4>');
	}
	/** blogImg height **/
	if ($('.blogImg, .portfolio-item-images, .projectImg').length) {
		$('.blogImg, .portfolio-item-images, .projectImg').each(function(){
			img_h = $(this).find('img').height();
			$(this).find('.mosaic-block').height(img_h);
		})
	}
	/** more-link  **/
	if ($('.more-link').length) {
		$('.more-link').addClass('button').wrap('<div class="blogMore" />').parent().before('<div class="clear" />');
	}
	/** RSS WIDGET ***/
	if($('.blogRight .widget_rss').length){
		$('.blogRight .widget_rss h5.title').addClass('rss-icon').find('img').remove();
		$('.blogRight .widget_rss > ul').wrap('<div class="blogRightM" />');
	}
	/** MENU WIDGET ***/
	if($('.blogRight .widget_nav_menu').length){
		$('.blogRight .widget_nav_menu > div').addClass('blogRightM');
	}
	/** CATEGORIES WIDGET ***/
	if($('.blogRight .widget_categories').length){
		$('.blogRight .widget_categories > ul').wrap('<div class="blogRightM" />');
	}
	/** META WIDGET ***/
	if($('.blogRight .widget_meta').length){
		$('.blogRight .widget_meta > ul').wrap('<div class="blogRightM" />');
	}
	/** CALENDAR WIDGET ***/
	if($('.blogRight .widget_calendar').length){
		$('.blogRight .widget_calendar > div').addClass('blogRightM');
		$('.blogRight .widget_calendar td a').addClass('button white').wrapInner('<span />');
		month = $('.blogRight .widget_calendar table caption').text();
		$('.blogRight .widget_calendar table caption').remove();
		title = $('.blogRight .widget_calendar > .title').html();
		$('.blogRight .widget_calendar > .title').html(title + ' ' + month);
		if(Cufon){
			Cufon.refresh('.blogRight .widget_calendar > .title');
		}
	}
	/** Portfolio dynamic ***/
	if ($('#portfolioList.dynamic').length) {
		
		$('#portfolioList a').click(function(event){
			event.preventDefault();
			items_class = $(this).removeClass('white').siblings('a').addClass('white').end()
							.children('span').attr('class');
							
			$('#portfolioList a cufon').each(function(){
				text = $(this).children('cufontext').text();
				$(this).parent().append(text);
			}).remove();
			Cufon.replace('#portfolioList a', { hover: true });
			
			if(items_class == 'all'){
				$('#projectsAll > div').removeClass('center').each(function(i){
					$(this).fadeIn(300);
					if ($(this).hasClass('project')) {//rewrite class center if need
						if( i%3 == 1)
							$(this).addClass('center');
					}
				});
			}
			else{
				$('#projectsAll > div').not('.' + items_class ).fadeOut(300);
				$('#projectsAll > div.' + items_class).removeClass('center').each(function(i){
					$(this).fadeIn(300);
					if ($(this).hasClass('project')) {//rewrite class center if need
						if( i%3 == 1)
							$(this).addClass('center');
					}
				});
			}
		})
	}
	if ($('#portfolio-more-images').length) {
		$('#portfolio-more-images').insertAfter('#portfolio-insert .line').show();
		$('.portfolio-item-images').each(function(){
			$(this).find('img').each(function(){
				if( parseInt($(this).width()) > 595){
					$(this).width(595);
				}
			});
			img_h = $(this).find('img').height();
			$(this).find('.mosaic-block').height(img_h);
		})
	}
	
});


(function($) {	
	//plugin
	jQuery.fn.topLink = function(settings) {
		settings = jQuery.extend({
			min: 1,
			fadeSpeed: 200
		}, settings);
		return this.each(function() {
			//listen for scroll
			var el = $(this);
			el.hide(); //in case the user forgot
			$(window).scroll(function() {
				if($(window).scrollTop() >= settings.min)
				{
					el.fadeIn(settings.fadeSpeed);
				}
				else
				{
					el.fadeOut(settings.fadeSpeed);
				}
			});
		});
	};
})(jQuery);


