/* Author: Emil Ivanov

*/
$(function(){
	$(document).click(function(e){
		if (!$(e.target).closest('.dropdown').length){
			$('.dropdown.active').removeClass('active');
		}
	});
	$('.dropdown .arrow').live('click',function(){
		$(this).closest('.dropdown').toggleClass('active');
	});
	$('.dropdown > li > ul > li').live('click',function(){
		$('.dropdown input').val($(this).text());
		$(this).closest('.dropdown').removeClass('active');
	});
	$('body').ajaxComplete(function(){
		Cufon.refresh();
		$('#mycarousel').jcarousel({
			buttonNextEvent:'mousedown',
			buttonPrevEvent:'mousedown',
			setupCallback:function(){
				$('#mycarousel .jcarousel-item:nth-child(2n)').addClass('jcarousel-second-item')
			}
		});
	});
	$('#loader-main').ajaxError(function(){
		$('#main').load('inc/404.php');
	});
//        $('#leftnav li a').live('click',function(e){
//                e.preventDefault();
//                url = $(this).attr('href');
//                $('#leftnav .active').removeClass('active');
//                $(this).closest('li').addClass('active');
//                if ($(this).closest('li').is(':first-child')){
//                        $('#loader-main').load('inc/' + url);
//                }
//                else {
//                        $('#loader-content').load('inc/' + url);
//                }
//                if (location.href.lastIndexOf('/') !=-1){
//                        firstpos=location.href.lastIndexOf('/')+1;
//                        lastpos=location.href.length;
//                        name=location.href.substring(firstpos,lastpos);
//                        loc = window.location.pathname.replace(name,'');
//                        window.history.pushState('','',loc + url);//无刷新更新地址哦
//                }
//        });
//	$('.button[class*=nav-btn]').live('click',function(e){
//		e.preventDefault();
//		url = $(this).attr('href');
//		$('.button.active').removeClass('active');
//		$(this).addClass('active');
//		$('#loader-main').load('inc/' + url);
//		if (location.href.lastIndexOf('/') !=-1){
//			firstpos=location.href.lastIndexOf('/')+1;
//			lastpos=location.href.length;
//			name=location.href.substring(firstpos,lastpos);
//			loc = window.location.pathname.replace(name,'');
//			window.history.pushState('','',loc + url);
//		}
//	});
	$('#mycarousel').jcarousel({
		buttonNextEvent:'mousedown',
		buttonPrevEvent:'mousedown',
		scroll:4,
		auto: 5,
        wrap: 'last',
		setupCallback:function(){
			$('#mycarousel .jcarousel-item:nth-child(2n)').addClass('jcarousel-second-item')
		}
	});
});
