jQuery(function(){

    // Superfish
    jQuery("ul.sf-menu").superfish({ 
    	delay: 800,
    	animation:   {opacity:'show',height:'show'},
    	pathClass:  'current-menu-parent',
    	autoArrows:    false 
    });
	
});

var slideshowSpeed = 18000;
var numLi = 0;

jQuery(document).ready(function() {

	jQuery('#header_cycle').cycle({
		timeout: 18000,
		speed: 2000
	});
	

	

	setTimeout(function() {
		jQuery('#events_info').fadeIn(1000);
	}, 3000);
	
	jQuery('#events_info').cycle({
		timeout: 18000,
		speed: 1000
	});
	
	
	jQuery('#slideBox')
	.cycle({
	    fx: 'scrollHorz',
	    speed: 500,
	    prev: '.previous',
	    next: '.next',
	    timeout: 0
	});		
	
	
	//if (_Page == "home" || _Page  == "event_top" || _Page == "involve") {
		
	if (_Page  == "event_top" || _Page == "involve") {
	
		////////// TOP / EVENTS SLIDE SHOW
		
		var interval;
		var activeContainer = 1;
		var currentImg = 0;
		var animating = false;
		var navigate = function(direction){
			// Check if no animation is running. If it is, prevent the action
			if (animating) {
				return;
			}
			
			// Check which current image we need to show
			if (direction == "next") {
				currentImg++;
				if (currentImg == photos.length + 1) {
					currentImg = 1;
				}
			}
			else {
				currentImg--;
				if (currentImg == 0) {
					currentImg = photos.length;
				}
			}
			
			// Check which container we need to use
			var currentContainer = activeContainer;
			if (activeContainer == 1) {
				activeContainer = 2;
			}
			else {
				activeContainer = 1;
			}
			
			showImage(photos[currentImg - 1], currentContainer, activeContainer);
			
		};
		
		var currentZindex = -1;
		var showImage = function(photoObject, currentContainer, activeContainer){
			animating = true;
			currentZindex--;
			
			// Set the background image of the new active container
			jQuery("#headerimg" + activeContainer).css({
				"background-image": "url(" + photoObject.image + ")",
				"display": "block",
				"z-index": currentZindex
			});
			
			// Hide the header text
			jQuery("#headertxt").css({
				"display": "none"
			});
			jQuery("#headerSub").css({
				"display": "none"
			});
			
			// Set the new header text
			jQuery("#headerdate").html(photoObject.firstline);
			jQuery("#headerLead").attr("href", photoObject.url).html(photoObject.secondline);
			jQuery("#headerSub").html(photoObject.sub);
			jQuery("#pictureduri").attr("href", photoObject.url).html(photoObject.title);
			
			//Fadeout
			jQuery("#headerimg" + currentContainer).fadeOut(function(){
				setTimeout(function(){
					jQuery("#headertxt").css({
						"display": "block"
					});
					jQuery("#headerSub").css({
						"display": "block"
					});
					animating = false;
				}, 200);
			});
		};
		
		var stopAnimation = function(){
			// Change the background image to "play"
			jQuery("#control").css({
				"background-image": "url(images/btn_play.png)"
			});
			
			// Clear the interval
			clearInterval(interval);
		};
		
		// We should statically set the first image
		navigate("next");
		
		// Start playing the animation
		interval = setInterval(function(){
			navigate("next");
		}, slideshowSpeed);
		
	}
	
	if (_Cate != "event") {
	
		jQuery('#gNavEvents').mouseover(function(){
			jQuery('#snaviGroup').show();
		});
		
		jQuery('#snaviGroup').mouseout(function(){
			jQuery('#snaviGroup').hide();
		});
	} else {
		if (_Page == "event_ylim") {
		
			
		}
	}	
	if (_Cate == "event" &&  _Page == "event_top") {
		//jQuery('#date').msDropDown();
		jQuery('#type').msDropDown();
		jQuery('#location').msDropDown({visibleRows:7, rowHeight:23});
		//jQuery(this).hide();
		//jQuery(':disabled').css("background-color","#FF0000");
	}
	if(_Cate == "feature"){
		var target ;
		numLi = jQuery("#fhscroll li").length;
		//jQuery('A[rel="feaThum"]').mouseover( function() {
		jQuery('div.imgHolder').mouseover( function() {	
	       target = jQuery(this).find("div.roTitle").show();
	    }).mouseout( function(){
			target = jQuery(this).find("div.roTitle").hide();
		}
		);
	
	}

});

function addValue(){
	var f = document.forms.getEventForm;
	var input = document.createElement("input");
	input.setAttribute("type", "hidden");
	input.setAttribute("name", "eeee");
	input.setAttribute("value", "987asd9f87s9df87");
	document.getElementById("getEventForm").appendChild(input);
	f.submit();
}

function ssshowValue(_str){
	//alert(_str);;
	//window.open("POST","http://yahoo.com", true);
	
	//window.open( "POST", _URL , '_self', '');
}
function showValue(_str){
	var f = document.forms.categorySelector;
	f.submit();
}









var curFSlide = 0;
var curFdist = -825;
var rLimit = 0;


function FscrollToRight(){
	rLimit = Math.floor(numLi / 5);
	//alert(rLimit);
	
	if(curFSlide < rLimit) curFSlide ++ ;
	jQuery('#fhscroll').animate({left: curFdist * curFSlide +"px"});
}
function FscrollToLeft(){
	
	if(curFSlide >= 1) curFSlide -- ;
	jQuery('#fhscroll').animate({left: curFdist * curFSlide +"px"});
}
function move(n){
	jQuery.scrollTo( n, 500);
}

