var reel_initial = function(){}

function slideshow_initCallback(carousel) {
	$('.slide_show .thumbs li:eq(0) img').attr('src', 'images/ui/ss_ctrl.png');
	var t_num = $('.slide_show .thumbs li').size();
	var t_width = (10*t_num)-3;
	var l_pos = parseInt(450-((t_width-3)*0.5));
	//
	$('.slide_show .thumbs ul').css('left', l_pos+'px');
	//
	$('.slide_show .thumbs img').bind('click', function() {
		carousel.scroll($.jcarousel.intval($(this).parent().index()+1));
	});
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	//
	window.setTimeout("reel_initial()", 1000); // You have to define this function in detail view
}

function gallery_initCallback(carousel) {
	$('.gallery .thumbs li:eq(0)').addClass('curr');
	$('.gallery .thumbs img').bind('click', function() {
		carousel.scroll($.jcarousel.intval($(this).parent().index()+1));
		$(this).parent().addClass('curr').siblings('.curr').removeClass('curr');
	});
	window.setTimeout("reel_initial()", 1000); // You have to define this function in detail view
}

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered before animation.
 */
function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
	//$('.slide_show .thumbs li img').attr('src', 'ss_ctrl.png');
	$('.slide_show .thumbs li img').css('left', '0px');
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
	//$('.slide_show .thumbs li:eq('+(idx-1)+') img').attr('src', 'ss_ctrl.png');
	var curr_num = 0;
	var t_num = $('.slide_show .thumbs li').size();
	//
	cycle_num = Math.floor(idx/t_num);
	//
	curr_num = idx-(t_num*cycle_num);
	//
	if(curr_num <= 0){
		curr_num = t_num;
	}
	//
	$('.slide_show .thumbs li:eq('+(curr_num-1)+') img').css('left', '-10px');
};

$(function() {
	$('.slide_show .slides').jcarousel({
		visible: 1,
		scroll: 1,
		auto: 5,
		wrap: 'circular',
		initCallback: slideshow_initCallback,
		itemVisibleInCallback: {
            onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
            onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
        },
		easing: 'easeInOutQuart',
		animation: 700,
		buttonPrevHTML: null,
		buttonNextHTML: null
	});
	
	$('.gallery .slides').jcarousel({
		visible: 1,
		scroll: 1,
		initCallback: gallery_initCallback,
		easing: 'easeInOutQuart',
		animation: 700,
		buttonPrevHTML: null,
		buttonNextHTML: null
	});
});

$(window).resize(function() {
	if($.browser.msie && $.browser.version < 8) {
		fixSlider();
	}
	//
	setBodyWidth();
});

function fixSlider() {
	var li_leng = $('#slider li').length;
	var ul_wid = $('#slider ul').width();
	var li_wid = Math.round(ul_wid/li_leng);
	$('#slider li').each(function() {
		$(this).css('width', li_wid);
	});
}

function setBodyWidth() {
	// SET BODY WIDTH IF BELOW 980
	var win_w = $(window).width();
	//
	if(win_w < 980){
		$('body').width(980);
	} else {
		$('body').width(win_w);	
	}
}

$(window).load(function () {
	//
	// SIDE BAR STUFF
	$('.icons li div a img').hover(function() {
    	var btn_idx = $(this).parent().parent().parent().index();
		var tab_wdt = 15+$('.icons li:eq('+btn_idx+') p').outerWidth();
		//alert(tab_wdt);
		$('.icons li:eq('+btn_idx+') p').css('display', 'block');
		$('.icons li:eq('+btn_idx+') p').css('left', '-'+tab_wdt+'px');
    }, function() {
		var btn_idx = $(this).parent().parent().parent().index();
		$('.icons li:eq('+btn_idx+') p').css('display', 'none');
		$('.icons li:eq('+btn_idx+') p').css('left', '40px');
    });
	//
	// SIZE THE FOOTER
	var win_h = $(window).height();
	var bdy_h = $('body').outerHeight();
	var ftr_h = $('#ftr').outerHeight()-40;
	//alert('win_h:'+win_h+'\nbdy_h:'+bdy_h+'\nftr_h:'+ftr_h);
	//
	if(bdy_h <= win_h){
		var set_ftr = win_h-(bdy_h-ftr_h);
		//alert('set_ftr:'+set_ftr);
		$('#ftr').height(set_ftr);
	}
	//
	// SET IMG BTN ROLLOVERS
	// alert($('div.btn').size());
	$('div.btn').each(function(index) {		
		$(this).css('display', 'block');
		//
		var btn_w = $(this).find("img").width();
		var btn_h = ($(this).find("img").height())*0.5;
		//
		//alert('btn:'+btn_w+'x'+btn_h+';');
		//		
		$(this).css('width', btn_w+'px');
		$(this).css('height', btn_h+'px');
		//
		$(this).hover(function() {
			$(this).find("img").css('top', '-'+btn_h+'px');
		}, function() {
			$(this).find("img").css('top', '0px');
		});
	});
	//
	// PREVENT ROLLOVER EFFECTS ON CURRENT
	$('#mnu_top ul li').each(function(index) {
		$(this).hover(function() {
			if($(this).attr("class") == 'curr'){
				$(this).css('background-image', 'none');
			}
			$(this).find("ul").css('display', 'block');
		}, function() {
			if($(this).attr("class") == 'curr'){
				$(this).css('background-image', 'url(images/ui/mnu_curr.gif)');
			}
			$(this).find("ul").css('display', 'none');
		});
	});
});

$(document).ready(function(){
	// SET BODY WIDTH
	setBodyWidth();
	//
	// SET COLORBOX LINKS
	$("a[rel='tmb']").colorbox({current:'Photo {current} of {total}'});
	$("a[rel='lnk']").colorbox({current:'Menu {current} of {total}'});
	$("a[rel='tst']").colorbox({current:'Testimonial {current} of {total}'});
});

// INVISIBLE FORM AND EMAIL CHECKER
function isEml($eml) {
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if($eml=='' || !emailReg.test($eml)) {
		return false;
	} else {
		return true;
	}
}
//
$(document).ready(function(){
	$('.frm_btn').bind('click', function() {
		//
		var sub_form = true;
		$('.frm input').removeClass('err');
		//
		if($("#frm_name").val() == ""){
			$("#frm_name").addClass('err');
			sub_form = false;
		}
		//
		if(!isEml($("#frm_email").val())){
			$("#frm_email").addClass('err');
			sub_form = false;
		}
		//
		if (!sub_form) {
			//alert('Error');
			return false;
		}
			//alert('Success');
			$("div.frm").wrap('<form id="enq_info" />');
			$('#enq_info').attr('action', 'mailers/cu.php');
			$('#enq_info').attr('method', 'post');
			$('#enq_info').submit();
			return true;
	});
});

