function listingSwitch() {
    var active = $('.activeLI');

    var next =  active.next().length ? active.next()
        : $('#upcomingEventsList li:first');

    active.css({opacity: 1.0})
        .animate({opacity: 0.0}, 1000, function() {
			$(this).removeClass('activeLI');
        });

    next.css({opacity: 0.0})
        .addClass('activeLI')
        .animate({opacity: 1.0}, 1000, function() {
            active.removeClass('activeLI last-active');
        });
}

function upcomingEventsWidget(){
	setInterval( "listingSwitch()", 5000 );
}

function fetchWidgetListings(){
	$.ajax({
 		   type: "POST",
 		   url: "admin/work.php",
 		   dataType: 'json',
 		   data: "typeofwork=fetchAll",
 		   success: function(msg){
 		     $.each(msg, function(index) {
 		       var eventDate = msg[index].date;
 					var splitDate = eventDate.split("-");
 					var formattedDate = splitDate[1]+"/"+splitDate[2];
     		      $("#upcomingEventsList").append("<li><a href='upcomingevents.php'><strong>"+msg[index].name+"</strong> - "+formattedDate+"</a></li>");
     		      $("#upcomingEventsList li:first").show().addClass("activeLI");
           });//end of each
          	upcomingEventsWidget();
 		   }
 		 });
}

function frontEndDetail(eventID){
	$.ajax({
		   type: "POST",
		   url: "admin/work.php",
		   dataType: 'json',
		   data: "typeofwork=fetchOne&eventID="+eventID,
		   success: function(msg){
			$.colorbox({html :"<div id='slideInfo'></div>"});
			
				$.each(msg, function(index) {
					var eventDate = msg[index].date;
					var splitDate = eventDate.split("-");
					var formattedDate = splitDate[1]+"/"+splitDate[2]+"/"+splitDate[0];
					$("#slideInfo").append("<div class='insertedContent'><div id='detailLeft'><div id='eventTitle'>"+msg[index].name+"</div><div id='eventDate'>"+formattedDate+"</div><img src='"+msg[index].image+"'><a href='"+msg[index].ticketLink+"' target='_blank'><div id='getTickets'>GET YOUR TICKETS NOW!</div></a></div><!-- end detailLeft --><div id='detailRight'>"+msg[index].description+"</div><!-- end detailRight --><div class='clear:left;'></div></div>");
					$("#slideInfo img").jScale({ls:'200px'});
					Cufon.replace('#detailLeft', { fontFamily: 'Proxima Nova' },{hover:true});
          		});//end of each
		   }
	});
}

function hoverFadeInit(items){
$(items).hover(function(){
	$(this).fadeTo(200, 0.7);	
},function(){
	$(this).fadeTo(200, 1.0);
}
);}// end of hoverFadeInit

function rightArrowInit(){
	$("#rightArrow").mouseup(function(){
	      $("#slides").stop().clearQueue();
	    }).mousedown(function(){
		if($(".homebase").length){
			$("#slides").prepend('<div id="leftArrow" class="proximaNova"><div></div></div>');
			hoverFadeInit("#leftArrow");
			leftArrowInit();
			$("#slides").removeClass("homebase");
			var totalWidth = 0;
				$('#slides img').each(function() {totalWidth += $(this).outerWidth( true )});
			var slideWidth = totalWidth-896;
				$("#slides").animate({marginLeft: "-"+slideWidth}, 5000 ,function(){
					$("#rightArrow").remove();
					$("#slides").addClass("farRight");
				});
		}
		else {
			var totalWidth = 0;
				$('#slides img').each(function() {totalWidth += $(this).outerWidth( true )});
			var leftMargin = Math.round($("#slides").css("margin-left").slice(0,-2)*1);
			var slideWidth = totalWidth-896;
				$("#slides").animate({marginLeft: "-"+slideWidth}, 5000, function(){
					$("#rightArrow").remove();
					$("#slides").addClass("farRight");
				});
		}
	    });
}

function leftArrowInit(){
	$("#leftArrow").mouseup(function(){
	      $("#slides").stop().clearQueue();
	    }).mousedown(function(){
		if($(".farRight").length){
			$("#slides").prepend('<div id="rightArrow" class="proximaNova"><div></div></div>');
			hoverFadeInit("#rightArrow");
			rightArrowInit();
			$("#slides").removeClass("farRight");
				$("#slides").animate({marginLeft: 0}, 5000 ,function(){
					$("#rightArrow").remove();
					$("#slides").addClass("farRight");
				});
		}
		else {
				$("#slides").animate({marginLeft: 0, duration: 5000},function(){
					$("#leftArrow").remove();
					$("#slides").addClass("homebase");
				});
		}
	    });
}

$(document).ready(function() {
	
	  Cufon.replace('#info', { fontFamily: 'Proxima Nova' },{hover:true});
	
	fetchWidgetListings();
	
	var currentPage = $("body").attr("class");	
	$("#nav_"+currentPage).hide();
	
	if (currentPage == "faq"){
		$('#backgroundFade').fadeOut(1000,function(){
			$("#container").fadeIn(1000);
			$('.scrollFix').scrollbar();
		});
	}
	else {
		$('#backgroundFade').fadeOut(1000,function(){
			$("#container").fadeIn(1000);
		});
	}
	
	$("#secondNav div, #mainNav div").bind("mouseover",function(){
		$(this).fadeTo(200, 0.7);	
	})
	
	$("#secondNav div, #mainNav div").bind("mouseout",function(){
		$(this).fadeTo(200, 1.0);	
	})
	
	Cufon.replace('.proximaNova', { fontFamily: 'Proxima Nova' },{hover:true});
	
	$('.scrollFix').scrollbar();
	
})
