﻿// document ready
$(function() {
	$(".labeler").labeler();
	$(".afalc").afalc();
	$("#content").moveClass("body");
	$("#content input").typeClass("input_type");
	$(".odd").oddEven();
	$(".tablestripe").oddEven({target:"tbody tr"});
	//$(".level1 ul li a").tooltiper({position:"left bottom tl", hideDelay:40, showDelay:200});
	initDatePicker();
	startLeadelements();
	videoPagination();
	page_tools();
	addClassToNavigation();	
	startTwitter();	
	$(".slidingpane").slidingPane({toggleClassOnComplete:true});		
    $('#secareasmall').jcarousel({ vertical: true,  visible: 1,   scroll: 1  })


   
});

// document load 
$(window).load(function() {
	$('#content a[href^="http://"]:not(#content .tweet_list a, .grid .thumbs a, a.logo, .logo a, .panel_designer_catwalks a, .panel_backstage a, .accordion li a )')
	  .attr({
	    target: "_blank", 
	    title: "Opens in a new window"
  }).append(' <span class="open-window">[^]</span>');
	
	
	
	createTabs();
});


function runCalendarCarousel() {
	
        $("#calendarcarousel").jcarousel({ visible: 1, scroll: 1}); 
	
}


function startTwitter() {
	   
	    $("#latest_tweet").tweet({
			username: "bfc",
			count: 12
	
		}).bind("loaded",function(){$(this).find(".tweet_list").jcarousel({  vertical: true,visible: 4, scroll: 3}); });
		

		$("#latest_mentions").tweet({ 
		  count: 12, fetch: 25, query: "@bfc",   
		  filter: function(t){ return ! /RT/.test(t["tweet_raw_text"]); },
           loading_text: "loading tweets...",
		     template: "{user}{time}{join}{text}{reply}"

	   }).bind("loaded",function(){$(this).find(".tweet_list").jcarousel({  vertical: true,visible: 4, scroll: 3}); $(".twittertabs").tabber();});
		
		
	}




function initDatePicker() {
	// Datepickers for date input fields
	$('input.date').datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true  });
}
 
 
 function page_tools() {
	$(".page_tools a").tooltiper({animateEffect:"fade", position:"center bottom",  opacity:0.7});

}


// Open an AJAX dialog
function openDialog(url,title,width,height) {
	// Width and height
	var w = 500;
	var h= 300;
	if(width) {
		w = width;	 
	}
	if(height) {
		h = height;	 
	}
	 // Reset the dialog
    $("#dialog").html('').dialog('destroy'); 
    // Set up dialog
    $("#dialog").dialog({
		width: w,
		height: h,
		modal: true,
		title: title,
		cache: false
    }); 
    // Fetch content
    $.ajax({
		type: "GET",
		url: url,
		data: "ajax=1",
		success: function(data){
			$("#dialog").html(data);
		}
    });
}

// Replace alrt boxes with a much nicer alternative
function ajaxAlert(msg) {
	if($('#alert').length == 0) {
		$("body").append('<div id="alert"></div>');	
	}
    $('#alert').dialog('destroy').html(msg).dialog({
		dialogClass: 'alert',
		width: 200,
		minHeight: 80,
		modal: true,
		cache: false,
		buttons: { "Ok": function() { $(this).dialog("close"); } }
    }); 
}

/* create tabs function - to allow for tabs to be called by other means */
function createTabs(){
	$(".tabs").tabber();
}

function printPage() {
    window.print();
}

function startLeadelements() {
  /* $('.cycle_slideshow').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev',
        next:    '#next',
        pager:   '.pager',
		timeout: 6000, 
        pagerAnchorBuilder: pagerFactory
    });

    function pagerFactory(idx, slide) {
        var s = idx > 10 ? ' style="display:none"' : '';
        return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
    };*/
	
	
	$('#home-accordion').liteAccordion({
				
					containerWidth : 930,           // width of accordion (px)
					containerHeight : 230,          // height of accordion (px)
					headerWidth : 30,               // width of tabs (px)
					 
					firstSlide : 1,                 // number of the first active slide (integer)
					onActivate : function() {},     // callback function triggered on tab click/mouseover (function)
					slideSpeed : 600,               // speed of slide animation (time/ms)
					slideCallback : function() {},  // callback function triggered after slide animation is complete (function)
					 
					autoPlay : false,               // automatically scroll through the slides, if true with pause on user click (boolean)
					pauseOnHover : true,           // *NEW in 1.1* - pause slides on hover
					cycleSpeed : 6000,              // time between slide activation (time/ms)
					 
					theme : 'basic',                // which theme to use ('basic', 'light'*, 'dark', or 'stitch'*)
					rounded : false,                // whether to use rounded corners or not** (boolean)
					enumerateSlides : true          // show slide number in tab
					
					
			}).find('li > div, h2 ').css({'position' : 'absolute', 'display' : 'block'});                   /*.find('figcaption:first').show();*/
}


function videoPagination() {	
   $('.video_list').cycle({
        fx:      'fade',
        timeout:  0,
        prev:    '#prev',
        next:    '#next',
        pager:   '.pager',
		timeout: 0, 
        pagerAnchorBuilder: pagerFactory
    });

    function pagerFactory(idx, slide) {
        var s = idx > 10 ? ' style="display:none"' : '';
        return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
    };
}






// add classes to navigation to display popup 

function addClassToNavigation() {	

	
$(".topnav ul li:not(div.nav_popup ul li)").hover(
	
	function() {	
				
		if($(this).hasClass("current")) 
		    {
			 return;			
			}
			 else {
															
				$(".topnav ul li:not(this)").removeClass("showPopup");
				$(this).addClass("showPopup");
				$(this).find("div.nav_popup").addClass("displayPopup").show();
			     }
	}, 
	
	function() {
		if($(".topnav ul li div.nav_popup").hasClass("displayPopup")) 
		
		    {
			$(".topnav ul li div.nav_popup").removeClass("displayPopup").hide();
			$(".topnav ul li").removeClass("showPopup");
		    }
	   }
		 
)};

