// Plugins

jQuery.fn.borderRadius = function(radius) {
	var m = "px";
	var defaults = {
		"r" : 5
	}		
	var opts = jQuery.extend(defaults, radius);		
	return this.each(function() {
		var el = jQuery(this);
		el.css({					
			"-moz-border-radius" : opts.r + m,
			"-webkit-border-radius" : opts.r + m,
			"border-radius" : opts.r + m
		});			
	});
}

jQuery.fn.shadow = function(options) {
	var m = "px";
	var s = " ";
	var defaults = {
		"offsetX" : 2,
		"offsetY" : 2,
		"blur" : 2,
		"color" : "#000000"			
	}		
	var opts = jQuery.extend(defaults, options);		
	return this.each(function() {
		var el = jQuery(this);
		el.css({					
			"-moz-box-shadow" : opts.offsetX + m + s + opts.offsetY + m + s + opts.blur + m + s + opts.color,
			"-webkit-box-shadow" : opts.offsetX + m + s + opts.offsetY + m + s + opts.blur + m + s + opts.color,
			"box-shadow" : opts.offsetX + m + s + opts.offsetY + m + s + opts.blur + m + s + opts.color
		});			
	});
}

jQuery.fn.opacity = function( options ) { 
	var defaults = { 
		"normal" : .5, 
		"active" : 1, 
		"animation" : false, 
		"animationSpeed"  : "slow"  
	}        
	var opts = jQuery.extend( defaults, options );
	return this.each(function() {
		var el = jQuery(this);
		// Init
		el.css({ "opacity" : opts.normal });
		// Hover event
		 el.hover(
			 function() {
				if ( opts.animation === false ) {
					el.css({ "opacity" : opts.active });
				}
				else {
					el.animate({ "opacity" : opts.active }, opts.animationSpeed  );
				}
			},
			function() {
				( opts.animation === true ) ? el.stop() : true;
				el.css({ "opacity" : opts.normal });
			}
		);
	});
}

jQuery.fn.hiddenBox = function(options) {
	var defaults = {
	}	
	var opts = jQuery.extend(defaults, options);		
	return this.each(function() {
		var trigger = jQuery(this);
		var rel = trigger.attr("rel");
		var box = jQuery("#" + rel);		
		trigger.bind("click", function(e) {
			box.slideToggle();
			jQuery(".closeBttn", trigger).toggle();
			return false;
		});
		jQuery("body").bind("click", function(e) {
			box.slideUp("slow");
			jQuery(".closeBttn", trigger).hide();
		});
	});
}

$(function() {
	var makeBeautiful = function (elem, borderRadius, shadowPosition, shadowSize, shadowColor) {
		var e = $(elem);
		e.css({
			"-moz-border-radius" : borderRadius + "px", 
			"-webkit-border-radius" : borderRadius + "px",
			"box-shadow" : shadowPosition + "px " + shadowPosition + "px " + shadowSize + "px #" + shadowColor,
			"-moz-box-shadow" : shadowPosition + "px " + shadowPosition + "px " + shadowSize + "px #" + shadowColor,
			"-webkit-box-shadow" : shadowPosition + "px " + shadowPosition + "px " + shadowSize + "px #" + shadowColor,
			"filter" : "progid:DXImageTransform.Microsoft.dropShadow(color=#" + shadowColor + ",offX=" + shadowPosition + ",offY=" + shadowPosition + ",positive=true)"
		});			
	}
	
	// lEvents Box - Header
	$("#levents-top-box-trigger").hiddenBox();
	$("#levents-top-box").borderRadius().shadow({"color" : "#555555"}).opacity({"normal" : .8});
	
	// Gallery - using jQuery Tools, Scrollable, http://flowplayer.org/tools/index.html
	var gallery = $("div.gallery");	
	
	if (gallery.length) {		
		gallery.scrollable({
			"size" : 3
		});
	
		var photos = $("div.items img");
		var description = $("div#photoDescription");
		var prefix = $("input[name='prefix']").val();
	
		photos.click(function() {
			var url = $(this).attr("src").replace("zx130y100_", prefix);
			var alt = $(this).attr("alt");
			var wrap = $("#photoBig").fadeTo("medium", 0.5);
			description.text(alt);
			var img = new Image();
			img.onload = function() {
				wrap.fadeTo("fast", 1);
				wrap.find("img").attr("src", url);
			};
			img.src = url;
		}).filter(":first").click();
	
		// Some CSS 3 Stuffs
		$(".gallery img").css({"-moz-border-radius" : "4px", "-webkit-border-radius" : "4px"});
		$("#photoBig").css({"-moz-border-radius" : "4px", "-webkit-border-radius" : "4px", "outline" : "1px solid #DDDDDD"});
	}
	
	// RegForm
	
	var regfortbl = $("#regTbl");
	
	if (regfortbl.length) {
		// Attendees Note
		var a = $("#attendees");
		var an = $("#attendeesNote");
		var anr = $(".anr");
		if ( a.val() > 1 ) { makeBeautiful("#attendeesNote", 1, 2, 3, "E4E4E4"); an.fadeIn(500); anr.css({"border" : "1px dotted red"}); }
		else { an.hide(); }
		a.bind("change", function() {
			if ( $(this).val() > 1 ) { makeBeautiful("#attendeesNote", 1, 2, 3, "E4E4E4"); an.fadeIn(800); anr.css({"border" : "1px dotted red"}); }
			else { an.hide(); anr.css({"border" : "1px solid #999999"}); }
		});
		
		// Errors
		var regformerr = $(".kforerror");
		var errorsDiv = $("#errors");
		var closebttn = '<div class="closeBttn big b red">X</div>';
		
		var isRegFree = $("#isRegFree").val(); // Free Reg, Patch
		
		regformerr.hide();
		
		if (regformerr.length) {
			var errors = new Array;			
			regformerr.each(function() { errors.push( $(this).html() ); });
			
			for ( keyVar in errors ) {
				errorsDiv.html( errorsDiv.html() + '<p class="errorsDivP">' + errors[keyVar] + '</p>' );
			}
			
			makeBeautiful("#errors", 7, 7, 15, "FFD4D4");
			errorsDiv.html( closebttn + errorsDiv.html() ).css({"opacity" : .9}).fadeIn(900);
			
			// Free Reg, Patch			
			if ( isRegFree == 1 ) {
				errorsDiv.css({"margin-top" : "-300px"});
			}			
			
			errorsDiv.click(function() { $(this).hide(); });
		}
		
		makeBeautiful(".regformbttn", 2, 3, 4, "E4E4E4");
		makeBeautiful(".regforminp", 1, 2, 3, "E4E4E4");		
	}	
	
	makeBeautiful(".regBttnBig", 4, 3, 5, "E4E4E4");
	makeBeautiful(".bpBttnBig", 4, 3, 5, "E4E4E4");
	
	makeBeautiful(".lecturerPhoto", 3, 4, 6, "E4E4E4");
	makeBeautiful(".partnerPhoto", 2, 3, 4, "E4E4E4");
});

// Native JavaScript Functions

function changeFont(inc,id) {
	var p = document.getElementById(id);
	if (p.style.fontSize) {
		var size = parseFloat(p.style.fontSize.replace("em", ""));
	} else {
		var size = 1;  // default value, see CSS
	}
    if (!inc) { size = 1; }
    if ((size + inc ) <= 1.8 && (size + inc) >= 0.6) { p.style.fontSize = size + inc + 'em'; }
}

// Banners

function vbaneri2(section, htmlstart, htmlend) {
	// Fix, bacause of validation problem
	if (!htmlstart.length && !htmlend.length) {
		var htmlstart = '<div class="b">';
		var htmlend = '</div>';
	}
	if (typeof(banners) == 'undefined') return false;
	if (!banners[section]) return false;
	if (showban1==1) {
		document.write(htmlstart);
		vbaneri(section);
		document.write(htmlend);
	}
}






