jQuery(function($){

//Responsive Image Slider
	$('.flexslider').flexslider({
		animation: "fade",              //String: Select your animation type, "fade" or "slide"
		slideDirection: "horizontal",   //String: Select the sliding direction, "horizontal" or "vertical"
		slideshow: true,                //Boolean: Animate slider automatically
		slideshowSpeed: 7000,           //Integer: Set the speed of the slideshow cycling, in milliseconds
		animationDuration: 600,         //Integer: Set the speed of animations, in milliseconds
		directionNav: true,             //Boolean: Create navigation for previous/next navigation? (true/false)
		controlNav: false,               //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
		animationLoop: true,            //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
		pauseOnAction: true,            //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
		pauseOnHover: false           //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
	});

//Fancybox
$(".iframe").fancybox({
	'type'			:	'iframe',
	'hideOnContentClick': false,
	'openEasing'		:	'swing',
	'closeEasing'		:	'swing',
	'openEffect'		:	'fade',
	'closeEffect'		:	'elastic',
	'openSpeed'		:	'normal', 
	'closeSpeed'		:	'fast',
	'padding'		: 	0,
	'scrolling'		:	'no',
	'autoSize'		:	true
});

$("ul.gallery li a").fancybox({
	'type'			:	'image',
	'openEasing'		:	'swing',
	'closeEasing'		:	'swing',
	'openEffect'	:	'fade',
	'closeEffect'	:	'elastic',
	'openSpeed'		:	'normal', 
	'closeSpeed'		:	'fast',
	'padding'		: 	0,
	'autoSize'		:	true
});

$(".event-img").fancybox({
	'type'			:	'image',
	'openEasing'		:	'swing',
	'closeEasing'		:	'swing',
	'openEffect'	:	'fade',
	'closeEffect'	:	'elastic',
	'openSpeed'		:	'normal', 
	'closeSpeed'		:	'fast',
	'padding'		: 	0,
	'autoSize'		:	true
});


// Carousel
	
	function px2num(s) {
		return (s.substr(0, s.length - 2) * 1);
	}
	
	// resize #carousel-offers
	no_offers = $("#carousel-offers .carousel-offerbox").size();
	width_of_single_offer = px2num($(".carousel-offerbox").css("width")) + 
							px2num($(".carousel-offerbox").css("margin-left")) + 
							px2num($(".carousel-offerbox").css("margin-right"));
	
	$("#carousel-offers").css("width", (no_offers * width_of_single_offer)); 
	hide_show_arrows();
	
	function hide_show_arrows() {
		var current_left = px2num($("#carousel-offers").css("left"));
		var min_left = ( -1 * px2num($("#carousel-offers").css("width")) + 3 * width_of_single_offer );
		var max_left = 0;
		if (current_left >= max_left) {
			$("#arrow-left").animate({'opacity' : 0.2});
			$("#arrow-left").css('cursor', 'auto');
		} else {
			$("#arrow-left").animate({'opacity' : 1});
			$("#arrow-left").css('cursor', 'pointer');
		}
		
		if (current_left <= min_left) {
			$("#arrow-right").animate({'opacity' : 0.2});
			$("#arrow-right").css('cursor', 'auto');
		} else {
			$("#arrow-right").animate({'opacity' : 1});
			$("#arrow-right").css('cursor', 'pointer');
		}
	}
	
	$("#arrow-right").click(function() {
		var current_left = px2num($("#carousel-offers").css("left"));
		var min_left = ( -1 * px2num($("#carousel-offers").css("width")) + 3 * width_of_single_offer );
		if ( current_left >  min_left ) {
			var new_left = current_left - width_of_single_offer;
			new_left = Math.max(new_left, min_left);
			$("#carousel-offers").stop().animate({left: new_left}, 500, function() {hide_show_arrows();});
		} 
		
	});
	
	$("#arrow-left").click(function() {
		var current_left = px2num($("#carousel-offers").css("left"));
		if ( current_left < 0 ) {
			var new_left = px2num($("#carousel-offers").css("left")) + width_of_single_offer;
			new_left = Math.min(new_left, 0);
			$("#carousel-offers").stop().animate({left: new_left}, 500, function() {hide_show_arrows();});
		}
	});
	
//Quicklinks Text Position

var textCon = $('.carousel-offerbox');
var textConHeight = $(textCon).height();
var tipHeight = $(textCon).find('hgroup').height();
var topPos = (textConHeight - tipHeight) / 2 - 10;
$(textCon).find('hgroup').css('top', topPos + 'px');


//Facebook Like Show/Hide

$('#facebook-like2').hide();
$('.facebook').mouseenter(function() {
	$('#facebook-like').hide();
	$('#facebook-like2').show();
}).mouseleave(function(){
	$('#facebook-like').show();
	$('#facebook-like2').hide();
});

//gallery controls
if ($('#gallery-page').size()>0) {
	
	$('#tj_container').gridnav({
		type	: {
			mode		: 'disperse', 	// use def | fade | seqfade | updown | sequpdown | showhide | disperse | rows
			speed		: 500,			// for fade, seqfade, updown, sequpdown, showhide, disperse, rows
			easing		: '',			// for fade, seqfade, updown, sequpdown, showhide, disperse, rows	
			factor		: '',			// for seqfade, sequpdown, rows
			reverse		: ''			// for sequpdown
		}
	});

	if (!$("html").hasClass("ie6")) {
	
		$("ul.gallery li a").append("<img src='img/gallery/magnify.png' class='magnify' />");
		$(".magnify").css({"opacity": 0.5});
		
		$("ul.gallery li a").hover(function(){
			$(this).children(".magnify").stop(true, true).animate({"opacity": 0});						
		}, function(){
			$(this).children(".magnify").stop(true, true).animate({"opacity": 0.5});	
		});
	}
	
}
$('.menu_table .oddRow').after('<div class="cb"></div>');


});// end jquery







