/* Pirobox */
$(document).ready(function() {
	$().piroBox_ext({
	piro_speed : 450,
		bg_alpha : 0.75,
		piro_scroll : true
	});
});


/* AJAX Contact Form*/
$(document).ready(function() {
	$('#contact-form').ajaxForm({
		target: '#error',
		success: function() {
		$('#error').fadeIn('fast');
		}
	});
	
	$(".cform-invoke").click(function() {
	$("#cform").slideToggle();
	return false;
  });

	$(".about-invoke").click(function() {
	$("#about_me").slideToggle();
	return false;
  });


  $( "#cform, #about_me" ).draggable();

});



/* Scrolling Filter Menu */
$(document).ready(function() {	

  //SRC: http://www.queness.com/post/256/horizontal-scroll-menu-with-jquery-tutorial

	//var colorOver = "#fff"; 
	var colorOver = $(".widget h3").css('color'); 
	var colorOut = '#1f1f1f';
	
	//Padding, mouseover
	var padLeft = '25px';
	var padRight = '50px';
  	
	//Default Padding
	var defpadLeft  = $('#menu li a').css('paddingLeft');
	var defpadRight = $('#menu li a').css('paddingRight');
	
	$('#menu li a').click(function () {
	var toGet = $(this).attr('href');
  });
		
	//Animate the LI on mouse over, mouse out
	$('#menu li').click(function () {	
		window.location = $(this).find('a').attr('href');
	}).mouseover(function (){
		
		//mouse over LI and look for A element for transition
		$(this).find('a')
		.animate( { paddingLeft: padLeft, paddingRight: padRight}, { queue:false, duration:200 } )
		.animate( { backgroundColor: colorOver }, { queue:false, duration:200 });

	}).mouseout(function () {
	
		//mouse oout LI and look for A element and discard the mouse over transition
		$(this).find('a')
		.animate( { paddingLeft: defpadLeft, paddingRight: defpadRight}, { queue:false, duration:200 } )
		.animate( { backgroundColor: colorOut }, { queue:false, duration:200 });
	});	
	
	//Scroll the menu on mouse move above the #sidebar layer
	$('#menu').mousemove(function(e) {

		//Sidebar Offset, Top value
		var s_top = parseInt($('#sidebar').offset().top);		
		
		//Sidebar Offset, Bottom value
		var s_bottom = parseInt($('#sidebar').height() + s_top);
	
		//Roughly calculate the height of the menu by multiply height of a single LI with the total of LIs
		var mheight = parseInt($('#menu li').height() * $('#menu li').length);
	
		//I used this coordinate and offset values for debuggin
		//$('#debugging_mouse_axis').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
		//$('#debugging_status').html(Math.round(((s_top - e.pageY)/100) * mheight / 2));
			
		//Calculate the top value
		//This equation is not the perfect, but it 's very close	
		var top_value = Math.round(( (s_top - e.pageY) /100) * mheight / 15 );
		
		//Animate the #menu by chaging the top value
		$('#menu').animate({top: top_value}, { queue:false, duration: 400});
  });

                allElements = jQuery("#canvas > a");                 
                $(allElements).animate({'opacity':'1.0'},250);
                $(allElements).each(function() {
                $(this).animate({'opacity':'0.4'},1250*(Math.random()+Math.random()));
                });

                $('#canvas > a').hover(function () {
                    var $this   = $(this);
                    $this.stop().animate({'opacity':'1.0'},120);
                },function () {
                    var $this   = $(this);
                    $this.animate({'opacity':'0.4'},400);
                });
});	
//jQuery.event.add(window, "load", resizeFrame);
//jQuery.event.add(window, "resize", resizeFrame);
//function resizeFrame() { $("#sidebar").css('height', $(window).height() ); }





/ * MALIHU Custom Scrollbars */
$(window).load(function() {
	mCustomScrollbars();
});

function mCustomScrollbars(){
	/* 
	malihu custom scrollbar function parameters: 
	1) scroll type (values: "vertical" or "horizontal")
	2) scroll easing amount (0 for no easing) 
	3) scroll easing type 
	4) extra bottom scrolling space for vertical scroll type only (minimum value: 1)
	5) scrollbar height/width adjustment (values: "auto" or "fixed")
	6) mouse-wheel support (values: "yes" or "no")
	7) scrolling via buttons support (values: "yes" or "no")
	8) buttons scrolling speed (values: 1-20, 1 being the slowest)
	*/
	$("#mcs_container").mCustomScrollbar("vertical",300,"easeOutCirc",1.05,"auto","yes","yes",15); 
}

/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}

/* function to load new content dynamically */
function LoadNewContent(id,file){
	$("#"+id+" .customScrollBox .content").load(file,function(){
		mCustomScrollbars();
	});
}

// Filterable
$(document).ready(function() {

	$('ul#menu a').click(function() {
		$(this).css('outline','none');
		$('ul#menu .current').removeClass('current');
		$(this).parent().addClass('current');
		
		var filterVal = $(this).attr('class').toLowerCase().replace(' ','-');
				
		if(filterVal == 'all') {
			$('#canvas a.concealed').show(400).removeClass('concealed');
		} else {
			
			$('#canvas a').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).hide(800).addClass('concealed');
				} else {
					$(this).show(400).removeClass('concealed');
				}
			});
		}
		return false;
	});
});
