$(document).ready(function () {
	 InitCufon();
});
/* *********************************************************************
 * Events
 * *********************************************************************/

 $('.datepicker').datepicker({ dateFormat: 'mm/dd/yy' });
function InitEvents () {
    $('.datepicker-inline').datepicker({
        firstDay: 1,
        dateFormat: 'dd-mm-yyyy',
        onSelect: function (dateText, inst) {
            id = $(this).attr('id');
            parts = id.split('-');
            id2 = parts[parts.length -1];
            $('#datepicker-target-id-' + id2).val(dateText);
        }
    });
}

function InitMenuEffects () {
    $('.menu li').hover(function () {
        			$(this).find('ul:first').css({'visibility': 'visible', 'display': 'none'}).slideDown();
    }, function () {
        $(this).find('ul:first').css({visibility: "hidden"});

    });
    
    // Look for active element
    indexStart = 1;
    $('#iconbar li').each( function(index) { 
            if ($(this).hasClass('active')) 
                indexStart = index;
    });
    // Initialize carousel plugin
    $('#iconbar').jcarousel({
        start:          indexStart,
        scroll:         7,
        buttonPrevHTML: '<span>&lt;</span>',
        buttonNextHTML: '<span>&gt;</span>',
        initCallback:   function (instance, state) {}
    });    
    instance = $('#iconbar').data('jcarousel')
    // Roll on active element
    if (indexStart >= 7) {
        if (!$.browser.webkit) {
            list = $('#iconbar .jcarousel-list');  
            number = list.css('left');
            list.css({'left': 0});
            list.delay(500).animate({left: '+=' + number}, 750, function () {});
        }
    }

}

/* *********************************************************************
 * Graphs
 * *********************************************************************/
function InitGraphs () {
	$('.visualize1').visualize({
			'type': 'bar',
			'width': '872px',
			'height': '250px'
	});

	$('.visualize2').visualize({
			'type': 'line',
			'width': '872px',
			'height': '250px'
	});

	$('.visualize3').visualize({
			'type': 'area',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize4').visualize({
			'type': 'pie',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize-T1').visualize({
			'type': 'bar',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize-T2').visualize({
			'type': 'line',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize-T3').visualize({
			'type': 'area',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize_dashboard').visualize({
			'type': 'bar',
			'width': '240px',
			'height': '100px'
	});
}

/* *********************************************************************
 * Slide Box
 * *********************************************************************/
function InitBoxSlide () {
    $('.box-slide-head').click(function (event) {

        tgt = $(event.target);
        if (tgt.hasClass('clickable')) {
            return;
        }
        
        body = $(this).next();
        
        if (!body.hasClass('box-slide-body')) {
            body = body.find('.box-slide-body');
        }
        //body = $(this).next('.box-slide-body');

        if (body.is(':visible')) {
            body.hide();
        }
        else {
            body.show();
        }
        
        return false;
    });
}

/* *********************************************************************
 * Misc
 * *********************************************************************/
function InitMisc () {
     $('.onFocusEmpty').focus(function () {
        $(this).val('');
    });
    
    $('.validate-form').validate({
          errorPlacement: function(error, element) {
            placeholder = $('#error-' + element.attr('rel'));
            if (placeholder.length) {
                    placeholder.html(error);
            }
            else {
                error.insertAfter(element);
            }
        }
    });   
}
/* *********************************************************************
 * Content Boxes
 * *********************************************************************/
function InitContentBoxes () {
	/* Checkboxes */
	$('.content-box .select-all').click(function () {
		if ($(this).is(':checked'))
			$(this).parent().parent().parent().parent().find(':checkbox').attr('checked', true);
		else
			$(this).parent().parent().parent().parent().find(':checkbox').attr('checked', false); 
	});
	
	/* Tabs */
	$('.content-box .tabs').idTabs();
}

/* *********************************************************************
 * Notifications
 * *********************************************************************/
function InitNotifications () {
	$('.notification .close').click(function () {
		$(this).parent().fadeOut(1000, function() {
			$(this).find('p').fixClearType ();
		});		
		return false;
	});
}
function InitCufon () {
 	Cufon.replace('.logo .title', { fontFamily: 'Zurich Cn BT', color: '-linear-gradient(#FFFFFF, #FFFFFF, #c0c0c0, rgb(200, 200, 200))', textShadow: '#FFFFFF 0px 1px'});
	Cufon.replace('.user-detail .name', { fontFamily: 'Zurich Cn BT' });
	Cufon.replace('.visualize-title', { fontFamily: 'Zurich Cn BT' });
	Cufon.replace('table caption', { fontFamily: 'Zurich Cn BT' });

	Cufon.replace('h1', { fontFamily: 'Zurich LtCn BT' });
	Cufon.replace('h2', { fontFamily: 'Zurich Cn BT' });
	Cufon.replace('h3', { fontFamily: 'Zurich LtCn BT' });
	Cufon.replace('h4', { fontFamily: 'Zurich Cn BT' });
	Cufon.replace('h5', { fontFamily: 'Zurich Cn BT' });
	Cufon.replace('h6', { fontFamily: 'Zurich LtCn BT' });
	Cufon.replace('h1 .label', { fontFamily: 'Zurich Cn BT' });
}

function InitGraphs () {
	$('.visualize1').visualize({
			'type': 'bar',
			'width': '872px',
			'height': '250px'
	});

	$('.visualize2').visualize({
			'type': 'line',
			'width': '872px',
			'height': '250px'
	});

	$('.visualize3').visualize({
			'type': 'area',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize4').visualize({
			'type': 'pie',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize-T1').visualize({
			'type': 'bar',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize-T2').visualize({
			'type': 'line',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize-T3').visualize({
			'type': 'area',
			'width': '872px',
			'height': '250px'
	});
	
	$('.visualize_dashboard').visualize({
			'type': 'bar',
			'width': '240px',
			'height': '100px'
	});
}

