// index slideshow
$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'fold',
		slices:15,
		animSpeed:500,
		pauseTime:4000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	$('#mycarousel').jcarousel({
        //itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        itemLoadCallback: mycarousel_itemLoadCallback
    });
});
function mycarousel_itemLoadCallback(carousel, state){
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }
    jQuery.get(
        'inc/karussel.inc.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};
function mycarousel_itemAddCallback(carousel, first, last, xml){
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
        carousel.add(first + i, jQuery(this).text());
    });
};
$(document).ready(function(){
	$("ul.topnav").hover(function(){ //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function(){
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});
	});
	$("#lbl_search").autocomplete('inc/search.php',{
		minChars: 1, width:216,
		formatItem: function(row) {
			return row[0];
		}	
	}).result(function(result, data) {
		$('#lbl_hidden').val(data[1]);
	});;
	$('input#suggest').result(function(event, data, formatted) {
		$("#lbl_search").html( !data ? "No match!" : "Selected: " + formatted);
	});
});
// index preview box
var xmlHttpObject = false;
if (typeof XMLHttpRequest != 'undefined') {
	xmlHttpObject = new XMLHttpRequest();
}
if (!xmlHttpObject) {
	try {
		xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e) {
		try {
			xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) {
			xmlHttpObject = null;
		}
	}
}

// head searchbox stop-autocomplete
function autocomplete() {
	document.getElementById('lbl_search').setAttribute('autocomplete','off'); 
}
