$(function(){
	// Auto Height Settings ------------------------------------------------------------------
	
	$('#sideLeft').css({
		minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
		height: 'auto !important',
		height: '100%'
	});
	$('#sideLeft2').css({
		minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
		height: 'auto !important',
		height: '100%'
	});
	$('#contentwrap').css({
		minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
		height: 'auto !important',
		height: '100%'
	});
	$('#bgimgrotetor').css({
		height : $('#wrapper').height() + 'px'
	});
	$(window).load(function(){
		$('#contentwrap').removeAttr('style');
		$('#sideLeft').removeAttr('style');
		$('#sideLeft').css({
			minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
			height: 'auto !important',
			height: '100%'
		});
		$('#sideLeft2').removeAttr('style');
		$('#sideLeft2').css({
			minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
			height: 'auto !important',
			height: '100%'
		});
		$('#contentwrap').css({
			minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
			height: 'auto !important',
			height: '100%'
		});
		$('#bgimgrotetor').css({
			height : $('#wrapper').height() + 'px'
		});
	});
	$(window).resize(function(){
		$('#contentwrap').removeAttr('style');
		$('#sideLeft').removeAttr('style');
		$('#sideLeft').css({
			minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
			height: 'auto !important',
			height: '100%'
		});
		$('#sideLeft2').removeAttr('style');
		$('#sideLeft2').css({
			minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
			height: 'auto !important',
			height: '100%'
		});
		$('#contentwrap').css({
			minHeight : $('#wrapper').height() - $('#header').height() - $('#footer').height() + 'px',
			height: 'auto !important',
			height: '100%'
		});
		$('#bgimgrotetor').css({
			height : $('#wrapper').height() + 'px'
		});
	});
	
	// carousel -----------------
	$("div.caruselwrap").jCarouselLite({
		mouseWheel: true,
		speed: 400,
		btnNext: ".next",
		btnPrev: ".prev",
		scroll: 1
	});
	$("div.caruselwrap2").jCarouselLite({
		mouseWheel: true,
		speed: 400,
		btnNext: ".next",
		btnPrev: ".prev",
		scroll: 1,
		visible: 6
	});
	// Fancy -----------------------------------------------------
	$("a.fancy").fancybox();
	$("a[rel=itemsgroup]").fancybox({
		padding : 10,
		margin : 40,
		opacity : false,
		modal : false,
		cyclic : false,
		scrolling : 'no',	// 'auto', 'yes' or 'no'

		width : 800,
		height : 640,

		autoScale : true,
		autoDimensions : true,
		centerOnScroll : false,

		ajax : {},
		swf : { wmode: 'transparent' },

		hideOnOverlayClick : true,
		hideOnContentClick : false,

		overlayShow : true,
		overlayOpacity : 0.8,
		overlayColor : '#000',

		titleShow : true,
		titlePosition : 'inside', // 'float', 'outside', 'inside' or 'over'
		titleFormat : null,
		titleFromAlt : false,

		transitionIn : 'fade', // 'elastic', 'fade' or 'none'
		transitionOut : 'fade', // 'elastic', 'fade' or 'none'

		speedIn : 800,
		speedOut : 400,

		changeSpeed : 300,
		changeFade : 'fast',

		easingIn : 'swing',
		easingOut : 'swing',

		showCloseButton	 : true,
		showNavArrows : true,
		enableEscapeButton : true,
		enableKeyboardNav : true
		
	});
	// Set BackGround ---------------------------------------------
	var iter = 0;
	var BgLI = $('#bgimgrotetor ul li').length;
	var bgTimeID = window.setInterval(function(){
		iter++;
		$('#bgimgrotetor ul li').css({'zIndex' : 'auto'});
		$('#bgimgrotetor ul li').eq(iter).css({'zIndex' : 3}).fadeIn(1500, function(){
			if(iter > 0){
				$('#bgimgrotetor ul li').eq(iter - 1).hide();
			}
			else {
				$('#bgimgrotetor ul li').eq(BgLI - 1).hide();
			}
			
			if(iter >= (BgLI - 1)){
				iter = -1;
			}
		});
		
	}, 8000);
	var running = false;
	$('a.setbg').click(function(){
		if(running){return false}
		running = true;
		$('#bgimgrotetor ul li').css({'zIndex' : 'auto'});
		$('#bgimgrotetor ul ' + $(this).attr('href')).css({'zIndex' : 3}).fadeIn(1500, function(){
			$('#bgimgrotetor ul li').not(this).hide();
			running = false;
		});
		clearInterval(bgTimeID);
		return false;
	});
	// Side Nav -------------------------------------------------------
	$('div.sidenav>ul>li.act').find('div').eq(0).slideDown('slow');
	$('div.sidenav>ul>li>span>a').click(function(){
		$('div.sidenav>ul>li').removeClass('act');
		$(this).parent('span').parent('li').addClass('act');
		$('div.sidenav>ul>li>div').not('div.sidenav>ul>li.act>div').slideUp('slow');
		$(this).parent('span').parent('li').find('div').eq(0).slideDown('slow');
		return false;
	});
	
});
