var ie = (document.all) ? 1 : 0;
var p = (ie) ? "filter" : "MozOpacity";

/* n is the element node
   v is the opacity value, from 0 to 100. */

function op(n,v){
    v = (ie) ? "alpha(opacity="+v+")" : v/100;
    n.style[p] = v;
}

$(document).ready(function(){
	
	// this initialises the demo scollpanes on the page.
	$('#pane1').jScrollPane();
	$('#pane2').jScrollPane({showArrows:true});
	$('#pane3, #pane4').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
    
	// this allows you to click a link to add content to #pane4 and shows how to 
	// reinitialise the scrollbars when you have done this.
	$('#add-content').bind(
		'click',
		function()
		{
			$('#pane4').append($('<p></p>').html($('#intro').html())).jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
		}
	);
	// and this allows you to click the link to reduce the amount of content in
	// #pane4 and reinitialise the scrollbars.
	$('#remove-content').bind(
		'click',
		function()
		{
			$('#pane4').empty().append($('<p></p>').html($('#intro').html())).jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
		}
	);
	
	$('#close_desc').click(function(){

		$(this).animate({
			right: "-30%"
		},'fast');
		
		$('#desc_container').animate({
			right: "-100%"
		},'fast');
		
		
		$('#open_desc').animate({
			right: "0%"
		},'fast');
		
		
			
	});
	
	$('#open_desc').click(function(){
	
		$(this).animate({
			right: "-100%"
		}, 0);
	
		$('#desc_container').animate({
				right: "-0%"
		}, 0);
		
		$('#close_desc').animate({
			right: "30%"
		},0);
		
		
	
	});

	
	        	
	$('#clicker img').toggle(//spacer.gif
		function(){
		
			$('.logo_container').animate({
				left: "-100%"
			},0);
			$('.mc_container').animate({
				left: "-100%"
			},0);
			
			$('#container').animate({
				left: "-30%"
			},0); 
			
			$('#close_desc').animate({
				right: "-30%"
			},0);
			
			$('#desc_container').animate({
				right: "-100%"
			},0);
			
			$('#open_desc').animate({
				right: "-100%"
			},0);
			
			$('#footer').animate({
			bottom: "-100px"
			},0);
			
		},
		function(){
			$('.logo_container').animate({
				left: "0%"
			},0);
			$('.mc_container').animate({
				left: "0%"
			},0);
			$('#container').animate({
				left: "30%"
			},0);
			
			$('#close_desc').animate({
				right: "30%"
			},0);
			
			$('#desc_container').animate({
				right: "0%"
			},0);
			
			$('#open_desc').animate({
				right: "-100%"
			},0);
			
			$('#footer').animate({
			bottom: "0px"
			},0);
			
		}
	);
	
	$.fn.supersized.options = {  
		startwidth: 1200,  
		startheight: 675,
		vertical_center: 1,
		slideshow: 1,
		navigation: 1,
		transition: 0, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
		pause_hover: 1,
		slide_counter: 0,
		slide_captions: 0,
		slide_interval: 7000 
	};
    $('#supersize').supersized(); 
   

	$('a img.captify').captify({
		// all of these options are... optional
		// ---
		// speed of the mouseover effect
		speedOver: 'fast',
		// speed of the mouseout effect
		speedOut: 'normal',
		// how long to delay the hiding of the caption after mouseout (ms)
		hideDelay: 0,	
		// 'fade', 'slide', 'always-on'
		animation: 'always-on',		
		// text/html to be placed at the beginning of every caption
		prefix: '',		
		// opacity of the caption on mouse over
		opacity: 1,					
		// the name of the CSS class to apply to the caption box
		className: 'caption-bottom',	
		// position of the caption (top or bottom)
		position: 'bottom',
		// caption span % of the image
		spanWidth: '100%'
		

	});
	
	$("#ac_search").autocomplete(data, {
		minChars: 0,
		max: 10,
		autoFill: true,
		mustMatch: false,
		matchContains: false,
		scrollHeight: 320,
		width: 196,
	  
	formatItem: function(item) {
	    return item.text;
	  }

	}).result(function(event, item) {
	  location.href = item.url;
	});
	
	
});

/**
 * This is the callback function which receives notification
 * about the state of the next button.
 */
function mycarousel_buttonNextCallback(carousel, button, enabled) {
    display('Next button is now ' + (enabled ? 'enabled' : 'disabled'));
};

/**
 * This is the callback function which receives notification
 * about the state of the prev button.
 */
function mycarousel_buttonPrevCallback(carousel, button, enabled) {
    display('Prev button is now ' + (enabled ? 'enabled' : 'disabled'));
};

/**
 * This is the callback function which receives notification
 * right after initialisation of the carousel
 */
function mycarousel_initCallback(carousel, state) {
    if (state == 'init')
        display('Carousel initialised');
    else if (state == 'reset')
        display('Carousel reseted');
};

/**
 * This is the callback function which receives notification
 * right after reloading of the carousel
 */
function mycarousel_reloadCallback(carousel) {
    display('Carousel reloaded');
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 */
function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
    display('Item #' + idx + ' is now the first item');
};

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 */
function mycarousel_itemFirstOutCallback(carousel, item, idx, state) {
    display('Item #' + idx + ' is no longer the first item');
};

/**
 * This is the callback function which receives notification
 * when an item becomes the first one in the visible range.
 */
function mycarousel_itemLastInCallback(carousel, item, idx, state) {
    display('Item #' + idx + ' is now the last item');
};

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 */
function mycarousel_itemLastOutCallback(carousel, item, idx, state) {
    display('Item #' + idx + ' is no longer the last item');
};

/**
 * 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) {
    // No animation on first load of the carousel
    if (state == 'init')
        return;

    jQuery('img', item);
};

/**
 * 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) {
    display('Item #' + idx + ' is now visible');
};

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 * Triggered before animation.
 */
function mycarousel_itemVisibleOutCallbackBeforeAnimation(carousel, item, idx, state) {
    jQuery('img', item);
};

/**
 * This is the callback function which receives notification
 * when an item is no longer the first one in the visible range.
 * Triggered after animation.
 */
function mycarousel_itemVisibleOutCallbackAfterAnimation(carousel, item, idx, state) {
    display('Item #' + idx + ' is no longer visible');
};

/**
 * Helper function for printing out debug messages.
 * Not needed for jCarousel.
 */
var row = 1;
function display(s) {
    // Log to Firebug (getfirebug.com) if available
    //if (window.console != undefined && typeof window.console.log == 'function')
      //  console.log(s);

    if (row >= 1000)
        var r = row;
    else if (row >= 100)
        var r = '&nbsp;' + row;
    else if (row >= 10)
        var r = '&nbsp;&nbsp;' + row;
    else
        var r = '&nbsp;&nbsp;&nbsp;' + row;

   // jQuery('#display').html(jQuery('#display').html() + r + ': ' + s + '<br />').get(0).scrollTop += 10000;

    row++;
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        scroll: 5,

        initCallback:   mycarousel_initCallback,
        reloadCallback: mycarousel_reloadCallback,

        buttonNextCallback:   mycarousel_buttonNextCallback,
        buttonPrevCallback:   mycarousel_buttonPrevCallback,

        itemFirstInCallback:  mycarousel_itemFirstInCallback,
        itemFirstOutCallback: mycarousel_itemFirstOutCallback,
        itemLastInCallback:   mycarousel_itemLastInCallback,
        itemLastOutCallback:  mycarousel_itemLastOutCallback,
        itemVisibleInCallback: {
            onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
            onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
        },
        itemVisibleOutCallback: {
            onBeforeAnimation: mycarousel_itemVisibleOutCallbackBeforeAnimation,
            onAfterAnimation:  mycarousel_itemVisibleOutCallbackAfterAnimation
        }
    });
});
