// vim: set ts=4 sts=4 sw=4 si noet:

$(document).ready(function() {
	/* slideshow images */
	$(".slidetabs")
		.fptabs(".images > div", {
			effect: 'slide',
			fadeOutSpeed: "slow",
			rotate: true
			})
		.slideshow({
			autoplay:true,
			interval:10000
			});

	/* Tab Slide Module */
	$("#flowpanes")
		.scrollable({
			circular: false,
			mousewheel: false,
			size: 1
			})
		.navigator({
			navi: "#flowtabs",
			naviItem: 'li',
			activeClass: 'current'
			});

	/* Tab Slide Content */
    $("#contentpanes")
        .scrollable({
            circular: false,
            mousewheel: false,
            size: 1
            })
       .navigator({
            navi: "#contenttabs",
            naviItem: 'li',
            activeClass: 'current'
            });

//	$(document).snowfall('clear');
//	$(document).snowfall({round : true, minSize: 5, maxSize:8}); // add rounded

	$("ul.tabs").fptabs("div.panes > div");

	$('#packages-tab').fptabs('#packages-tab-panes > div', {
		effect: 'ajax',
	});

	/* Partner Slider */
	$(".scrollable").scrollable({circular: true}).autoscroll({ autoplay: true,interval:8000});
	$(".video-scrollable").scrollable({
		circular: true,
		next: ".prev.browse.right",
		prev: ".prev.browse.left",
		speed: 400
		});
	$(".prodlineupscrollable").scrollable({ vertical: true, mousewheel: true });
	/* Slideshow2 */
	$("#main")
		.scrollable({
			vertical: true,
			circular: true,
			keyboard: 'static',
			onSeek: function(event, i) {
				}
			})

		.navigator("#main_navi")
			.autoscroll({
				autoplay: true,
				interval:50000
			});

	// when page loads setup keyboard focus on the first horzontal scrollable
	//horizontal.eq(0).data("scrollable").focus();

	/* Floating Social Button*/
	var $sidebar = $("#floatingsocial");
	if ($sidebar.length > 0) {
		$window = $(window),
		offset = $sidebar.offset(),
		topPadding = 15;

		$window.scroll(function() {
			if ($window.scrollTop() > offset.top) {
				$sidebar.stop().animate({
					marginTop: $window.scrollTop() - offset.top + topPadding
				});
			} else {
				$sidebar.stop().animate({
					marginTop: 0
				});
			}
		});
	}

	// media selection for embedding in tinymce
	$('#attachments-browser').delegate('a.select', 'click', fmweb.tinymce.selectAttachment);

	$('a[rel*=facebox]').facebox({
		loadingImage : fmweb.cfg.base + '/css/facebox/loading.gif',
		closeImage   : fmweb.cfg.base + '/css/facebox/closelabel.gif'
	});

	// setup tooltips
	/*
	$('.small-tip').tooltip();
	$('.big-tip').tooltip({tipClass: 'tooltip-big'});
	$('.vote-sms').tooltip({
		relative: true
	});

	$('.icon-tip').tooltip({
		relative: true
	});
	*/


/* Vertical Accordion menu */
function initMenu() {
  $('.accordionmenu ul').hide();
  $('.accordionmenu ul:first').show();
  $('.accordionmenu li a').mouseover(
    function() {
        var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
	          return false;
       }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
	        $('.accordionmenu ul:visible').slideUp('normal');
	        checkElement.slideDown('normal');
	        return false;
       }
    }
    );
  }
initMenu();

/* Overlay */
$("a[rel]").overlay();

/* Promotion Slides */
	/* This code is executed after the DOM has been completely loaded */
	
	var totWidth=0;
	var positions = new Array();

	$('#promoslides .promoslide').each(function(i){

	/* Traverse through all the slides and store their accumulative widths in totWidth */
												
	positions[i]= totWidth;
	totWidth += $(this).width();

	/* The positions array contains each slide's commulutative offset from the left part of the container */
																						
	if(!$(this).width())
		{
		alert("Please, fill in width & height for all your images!");
		return false;
		}
	});
						
	$('#promoslides').width(totWidth);
	/* Change the cotnainer div's width to the exact width of all the slides combined */
	$('#promomenu ul li a').click(function(e,keepScroll){
	/* On a thumbnail click */
	$('li.menuItem').removeClass('act').addClass('inact');
	$(this).parent().addClass('act');
	var pos = $(this).parent().prevAll('.menuItem').length;
	$('#promoslides').stop().animate({marginLeft:-positions[pos]+'px'},450);
	/* Start the sliding animation */
	e.preventDefault();
	/* Prevent the default action of the link */
	// Stopping the auto-advance if an icon has been clicked:
	if(!keepScroll) clearInterval(itvl);
	});
	$('#promomenu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	/*****
	*
	*	Enabling auto-advance.
	*
	****/
																					 
	var current=1;
	function autoAdvance()
	{
		if(current==-1) return false;
		$('#promomenu ul li a').eq(current%$('#promomenu ul li a').length).trigger('click',[true]);	
		// [true] will be passed as the keepScroll parameter of the click function on line 28
		current++;
	}
																										// The number of seconds that the slider will auto-advance in:
	var changeEvery = 10;
	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);
																									/* End of Promotion Slides*/

      //stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
      if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
      {
           $(".floatbar").css("position", "static");
      };


});

html5media.configureFlowplayer = function(tag, element, config) {
	key : '#$a48dc8389f75d02d017';
	config.plugins.controls.fullscreen = true;
	config.plugins.controls.time = false;
	config.showErrors = false;
}

