/**
 * @package Slamfest
 * @author Bonsai Media / Christian Duller
 * @version 1.0
 * @copyright 2011, Bonsai Media
*/

/* Slamfest object which contains all our functions/etc */
var obj = obj || {};

/* document ready.... magic happens here */
$(document).ready(function(){
	obj.init();
});

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////


/**
 * Initialise the Slamfest website and various features.
 */
obj.init = function() {
	
	this.menu();
	this.initCufon();
	this.fixImage();
	
	if($(".slides").length)
			this.slideSwitch(".slides");
	
	// add shadow in IE
	if ($.browser.msie){
		$('.shdw').boxShadow( 3, 3, 50, "#000000");
	}
	
	/*		
	if($("#vldt_frm").length){
			$("#vldt_frm").validate();
		}
	*/
	}
	
	/** 
	 * create home page slideshow
	 */
	obj.slideSwitch = function(elem) {
		function animate(){
			var $active = $(elem+' img.active');			
				if ( $active.length == 0 )  $(elem+' img:last');	
			var $next =  $active.next().length ? $active.next(): $(elem+' img:first');
						
			$active.addClass('last-active');
						
			$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function(){
					$active.removeClass('active last-active');
				});
		};
		// init
		var timeout;
			timeout = setInterval(function(){
					animate();
			},4000);
	}
			
	/** 
	 * Initialise Cufon text replacement
	 */
	obj.initCufon = function() {
		//Cufon.replace('#menu ul a',{hover: true});
		Cufon.replace('#event_holder h2, .left_panel h3, .right_panel h4, .right_panel h1');
	}

	/** 
	 * Initialise menu
	 */
	obj.menu = function() {
		$("#menu ul").hide();
		$("#menu li").hover(
			function(){ $("ul", this).fadeIn("fast");
			}, 
			function() { 
				$("ul", this).fadeOut("fast");
			} 
		);
		if (document.all) {
			$("#menu li").hoverClass ("sfHover");
		}
	}
	
	/** 
	 * Fix png image transparency
	 */
	obj.fixImage = function() {
		if ($.browser.msie){
			userAgent = $.browser.version;
			userAgent = userAgent.substring(0,userAgent.indexOf('.'));
			if(userAgent==6){
				$(".pngfix").pngfix();
			}
		}
	}
/** 
 * Initialise menu
 * hover class
 */
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};


$.fn.pngfix = function(){
	$(this).each(function() {
		var elem = $(this);
		var iebg = $(this).attr('src');
				elem.css({'background-image':'none',
						  'width':elem.width(),
						  'height':elem.height()});
				
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "', sizingMethod='scale')";
				elem.attr('src', 'images/blank.gif');
	});
};

/**
 * Initialises box shadow
 */
$.fn.boxShadow = function(xOffset, yOffset, blurRadius, shadowColor) {
		return this.each(function(){
			$(this).css({
				position: "relative",
				zoom: 1,
				zIndex: "2"
			});
	
			$(this).parent().css({
					position:	"relative",
					float: 'left'
			});	
			var div=$(document.createElement("div")).addClass('itemtoremove');
			//var div= document.createElement("div");
			//alert($(this).parent().attr('class'));
			$(this).parent().append(div);
			var _top, _left, _width, _height;
			if (blurRadius != 0) {
				$(div).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelRadius="+(blurRadius)+", enabled='true')");
				_top = 		yOffset-blurRadius+5;
				_left =		xOffset-blurRadius+2;
				_width =		$(this).outerWidth()-4;
				_height =	$(this).outerHeight()-4;
			} else {
				_top = 		yOffset;
				_left =		xOffset;
				_width = 	$(this).outerWidth();
				_height = 	$(this).outerHeight();
			}
			$(div).css({
				'position': "absolute",
				top: _top+'px',
				left: _left+'px',
				width: _width+'px',
				height: _height+'px',
				background:	shadowColor,
				zIndex: 1
			});
		//alert('top:'+_top+' left:'+_left+' width:'+_width+' height:'+_height);
		});
};
