$(function(){
	
	//setup suckerfish navigation
	$('ul.sf-menu').superfish({
		pathLevels: 3,
		speed: 0,
		autoArrows: false
	});	
	
	/*
	 * setup page banner slide shows
	 */
	$('#page_banner').cycle({
		prev:   '#prev',
		next:   '#next',
		timeout: 6000,
		speed: 4000
	});
	$('#page_banner').css("display", "block");
	/*$('#home_banner').cycle({
		prev:   '#prev',
		next:   '#next',
		timeout: 6000,
		speed: 4000,
		fx: 'scrollLeft',
		pause: 1
	});*/
	$('#home_banner_content').cycle({ 
		fx: 'scrollLeft',
		speed:2000, 
		timeout:7000,
		pager:'#home_banner_pager ul',
		//allowPagerClickBubble: true,
		fastOnEvent: true,
		pagerAnchorBuilder: function(idx, slide){ 
			return '<li><a href="#"></a></li>'; 
			//return '#nav li:eq(' + (idx) + ') a';

		},
		pause:1
	});
	$('#home_banner').css("display", "block");
	
	$('#testimonials_slideshow').cycle({ 
		fx: 'fade',
		speed:1000, 
		timeout:7000,
		pause:1
	});
	$('#testimonials_slideshow li').css("display", "block");
	
	$('#what_we_do_widget').cycle({ 
		fx: 'fade',
		speed:1000, 
		timeout:3000,
		pause:1
	});
	
	/*
	 * add styles to every first p tag after H1 in the main content
	 */
	$('div#main h1+p').addClass("first_para");	 
	// we need this extra rule incase a page banner is present
	$('div#page_banner+p').addClass("first_para");	 
	
	/*
	* setup smooth scroll on back to top links
	*/
	$('#top_link').click(function(e) {
		e.preventDefault();
		$.scrollTo(0,300);
	});	
	//CONTACT
    $("#enquiry_modal,a[href='http://enquiry']").colorbox({
		href:"/cd-content/themes/intelligent_capture/includes/enquiry_form.php", 
		initialWidth:635, 
		initialHeight:365, 
		width:635, 
		height:365, 
		transition:"fade", 
		opacity:0.7, 
		speed:0
	});	
	$("a[href='http://newsletter']").colorbox({
		href:"/cd-content/themes/intelligent_capture/includes/newsletter-signup.php", 
		initialWidth:450, 
		initialHeight:350, 
		width:450, 
		height:350, 
		transition:"fade", 
		opacity:0.7, 
		speed:0
	});
	
	// get cookie
	var startSize = jQuery.cookie('fontSize');
	//alert(startSize);
	ic_scripts.changeBaseSize(startSize);
	$('#small_text a').click(function() { ic_scripts.changeBaseSize('60%') });
	$('#medium_text a').click(function() { ic_scripts.changeBaseSize('76%') });
	$('#large_text a').click(function() { ic_scripts.changeBaseSize('110%') });
	
	
});

var ic_scripts = function() {
	
	var leaveCookie = function() {
		var fontSize = $('body').css('font-size'); 	   
	 	jQuery.cookie('fontSize', fontSize);  
	};
	
	var changeBaseSize = function( baseSize ) {
		jQuery('body').css('font-size', baseSize);
		// set cookie	
	 	jQuery.cookie('fontSize', baseSize, { path: '/' });
		switch( baseSize ){
			case '60%' :
				$('#small_text').addClass('current');
				$('#medium_text').removeClass('current');
				$('#large_text').removeClass('current');
				break;
			case '76%' :
				$('#medium_text').addClass('current');
				$('#small_text').removeClass('current');
				$('#large_text').removeClass('current');
				break;	
			case '110%' :
				$('#large_text').addClass('current');
				$('#small_text').removeClass('current');
				$('#medium_text').removeClass('current');
				break;	
		}
	};
	
	return {
		leaveCookie : leaveCookie,
		changeBaseSize : changeBaseSize
	};
	
}();
