jQuery(document).ready(function() {
	
	//dropDownMenu();
	
	notebook_slider('.notebook_slider', 4000);
	portfolio();
	changeCSS();
	jQuery('.tab_content').css({display: 'none'});
        jQuery('.tab_active').css({display: ''});
});

function show_tab(obj)
{
    if(obj == undefined || obj == '')
    {
        return false;
    }
    jQuery('.tab_content').css({display: 'none'});
    jQuery(obj).fadeIn();
}

function dropDownMenu() {
	
	jQuery("#menu ul li ul").css({display: "none"});
	  
	jQuery("#menu ul li").hover(function() {
		jQuery(this).find('ul:first').stop().css({ display: 'inline', opacity: 0 }).animate({ opacity: 1 }, 300); //Slides down when hover the UL
		jQuery(this).children('a').addClass("hovered"); //Adds a hovered class, so you can see the menu path you are following
	}
	,function() {
		jQuery(this).find('ul:first').stop().animate({ opacity: 0 }, 300); //Slides up on mouseleave
		jQuery(this).children('a').removeClass("hovered"); //removes the hovered class.
	});
	
}

function notebook_slider(obj, $time) {
	
	//adds the current class to the first slide
	jQuery(obj + ' ul li:first').addClass('current');
	
	//hovering effect
	jQuery(obj + ' ul li').hover(function() {
		
		jQuery(this).children('div').css({ opacity: 0, display: 'block' }).stop().animate({ opacity: 1 }, 300);
		
	}, function() {
		
		jQuery(this).children('img').stop().animate({ opacity: 1 }, 200);
		jQuery(this).children('div').stop().animate({ opacity: 0 }, 200);
		
	});
	
	if(typeof(isHovered) == 'undefined') { var isHovered = 0; }
	//If no item has been hovered yet, the variable isHovered doesn't exist, so we create it. 
		
	jQuery(obj).hover(function() { // Whenever an item is hovered
		isHovered = 1; //Setting isHovered 1, we stop the autsliding from going on
	}, function() {
		isHovered = 0;//Setting isHovered 1, we make the autsliding go on
	});
	
	setInterval(function() { if(isHovered == 0) { nextNoteSlide(); } }, $time);
	
	jQuery(obj + ' .left').click(function(){ prevNoteSlide(obj); });
	jQuery(obj + ' .right').click(function(){ nextNoteSlide(obj); });
	
}

function nextNoteSlide(obj) {
	
	$currentNote = jQuery(obj + ' ul li.current');
	$nextNote = jQuery(obj + ' ul li.current').next();
	
	//alert($nextNote.length);
	
	if($nextNote.length == 00) {
		
		$nextNote = jQuery(obj + ' ul li:first');
		
	}
	
	$nextNote.addClass('next');
	$nextNote.stop().css({ left: '-171px' }).animate({ left: 0 }, {duration: 800, easing: 'easeOutBounce', complete: function() {
		
		$currentNote.removeClass('current').css({ left: '171px' });
		$nextNote.removeClass('next').addClass('current');
		
	}});
	
	
}

function prevNoteSlide(obj) {
	
	$currentNote = jQuery(obj + ' ul li.current');
	$nextNote = jQuery(obj + ' ul li.current').prev();
	
	//alert($nextNote.length);
	
	if($nextNote.length == 00) {
		
		$nextNote = jQuery(obj + ' ul li:last');
		
	}
	
	$nextNote.addClass('next');
	$nextNote.stop().animate({ left: 0 }, {duration: 800, easing: 'easeOutBounce', complete: function() {
		
		$currentNote.removeClass('current').css({ left: '171px' });
		$nextNote.removeClass('next').addClass('current');
		
	}});
	
	
}

function portfolio() {
	
	jQuery('.portfolio_image ul li').hover(function() {
		
		jQuery(this).children('img').stop().animate({ opacity: .7 }, 400);
		jQuery(this).children('div').stop().css({ display: 'block', opacity: 0 }).animate({ opacity: 1 }, 400);
		
	}, function() {
		
		jQuery(this).children('img').stop().animate({ opacity: 1 }, 250);
		jQuery(this).children('div').stop().animate({ opacity: 0 }, 250);
		
	});
	
}

function changeCSS() {
	
	jQuery('#dark_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_dark.css');
			
			//Cufon.replace('#div_content h1, #div_content h2,  #div_content h3,  #div_content h4,  #div_content h5,  #div_content h6, #footer h3', { fontFamily: 'HelveticaNeue LT 67 MdCn' });
			
			//Cufon.replace('h1 em, h2 em, h4 em, h3 em, h5 em, h6 em', { fontFamily: 'HelveticaNeue LT 45 Light' });
;
	});
	
	jQuery('#blue_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_blue.css');
;
	});
	
	jQuery('#green_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_green.css');
;
	});
	
	jQuery('#orange_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_orange.css');
;
	});
	
	jQuery('#brown_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_brown.css');
;
	});
	
	jQuery('#dark_green_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_dark_green.css');
;
	});
	
	jQuery('#cyan_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_cyan.css');
;
	});
	
	jQuery('#grey_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_grey.css');
;
	});
	
	jQuery('#pink_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_pink.css');
;
	});
	
	jQuery('#purple_css').click(function() {
		jQuery('link:first').attr("href", 'css/style_purple.css');
;
	});
	
}

function format_currency(num)
{
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + num + '.' + cents);
}

function msgbox(title, msg, type)
{

    if(type == undefined || type == '')
    {
        type    = 'error';
    }
    if(title == '')
    {
        if(type == 'error')
        {
            title   = 'Opps, you\'ve got an error!';
        }
        else
        {
            title   = 'Success!';
        }
    }
    jQuery('#div_general_msgbox').addClass(type);
    jQuery('#div_general_msgbox .title').html(title);
    jQuery('#div_general_msgbox .msg').html(msg);

    jQuery('#div_general_msgbox_stalker').animate({
        height: jQuery('#div_general_msgbox').height() + 'px'
    });

    jQuery('#div_general_msgbox').delay(300).fadeIn();
}
/* ---------------------------------------------------------------------------------------------------------------------------------------
 * INIT
 * -------------------------------------------------------------------------------------------------------------------------------------- */
function init_msgbox()
{
    def_opacity = 0.7;
    closing_msgbox   = false;
    jQuery('#div_general_msgbox').unbind('click').bind('click', function(){
        closing_msgbox   = true;
        jQuery('#div_general_msgbox_stalker').animate({
            height: '0px'
        })
        jQuery('#div_general_msgbox').fadeOut(global.anim_fast, function(){
            closing_msgbox   = false;
        });
    });

    jQuery('#div_general_msgbox').hover(
        function(){
            if(!closing_msgbox)
            {
                jQuery(this).stop().animate({opacity: 1});
            }
        },
        function(){
            if(!closing_msgbox)
            {
                jQuery(this).stop().animate({opacity: def_opacity});
            }
        }
    );

    jQuery(window).scroll(function(){
        if(jQuery(window).scrollTop() > global.topbar_size)
        {
            def_opacity = 0.5
            jQuery('#div_general_msgbox').css({
                opacity : def_opacity,
                position: 'fixed',
                top     : '0px'
            });
        }
        else
        {
            jQuery('#div_general_msgbox').css({
                opacity : 0.9,
                position: '',
                top     : ''
            })
        }
    });
}
/* -----------------------------------------------------------------------
 * INIT input assist
 * ----------------------------------------------------------------------- */
function init_input_assist(obj,assistText,clear)
{
    if(clear == undefined)
    {
        clear = true;
    }

    if(jQuery(obj).val() == '' || jQuery(obj).val() == assistText)
    {
        jQuery(obj).addClass('input_assist').val(assistText);
    }
    else
    {
        jQuery(obj).removeClass('input_assist');
    }
    jQuery(obj).focus(function(){
        if(jQuery(obj).val() == assistText && clear)
        {
            jQuery(obj).val('');
        }
        jQuery(obj).removeClass('input_assist');
    }).blur(function(){
        if(jQuery(obj).val() == '' || jQuery(obj).val() == assistText)
        {
            jQuery(obj).addClass('input_assist').val(assistText);
        }
        else
        {
            jQuery(obj).removeClass('input_assist');
        }
    })
}


