/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				//if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);



/*!
 * jQuery corner plugin: simple corner rounding
 * Examples and documentation at: http://jquery.malsup.com/corner/
 * version 1.98 (02-JUN-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */

/**
 *  corner() takes a single string argument:  $('#myDiv').corner("effect corners width")
 *
 *  effect:  name of the effect to apply, such as round, bevel, notch, bite, etc (default is round). 
 *  corners: one or more of: top, bottom, tr, tl, br, or bl. 
 *           by default, all four corners are adorned. 
 *  width:   width of the effect; in the case of rounded corners this is the radius. 
 *           specify this value using the px suffix such as 10px (and yes, it must be pixels).
 *
 * @name corner
 * @type jQuery
 * @param String options Options which control the corner style
 * @cat Plugins/Corner
 * @return jQuery
 * @author Dave Methvin (http://methvin.com/jquery/jq-corner.html)
 * @author Mike Alsup   (http://jquery.malsup.com/corner/)
 */

;(function($){var expr=(function(){if(!$.browser.msie)return false;var div=document.createElement('div');try{div.style.setExpression('width','0+0');}
catch(e){return false;}
return true;})();function sz(el,p){return parseInt($.css(el,p))||0;};function hex2(s){var s=parseInt(s).toString(16);return(s.length<2)?'0'+s:s;};function gpc(node){for(;node&&node.nodeName.toLowerCase()!='html';node=node.parentNode){var v=$.css(node,'backgroundColor');if(v=='rgba(0, 0, 0, 0)')
continue;if(v.indexOf('rgb')>=0){var rgb=v.match(/\d+/g);return'#'+hex2(rgb[0])+hex2(rgb[1])+hex2(rgb[2]);}
if(v&&v!='transparent')
return v;}
return'#ffffff';};function getWidth(fx,i,width){switch(fx){case'round':return Math.round(width*(1-Math.cos(Math.asin(i/width))));case'cool':return Math.round(width*(1+Math.cos(Math.asin(i/width))));case'sharp':return Math.round(width*(1-Math.cos(Math.acos(i/width))));case'bite':return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));case'slide':return Math.round(width*(Math.atan2(i,width/i)));case'jut':return Math.round(width*(Math.atan2(width,(width-i-1))));case'curl':return Math.round(width*(Math.atan(i)));case'tear':return Math.round(width*(Math.cos(i)));case'wicked':return Math.round(width*(Math.tan(i)));case'long':return Math.round(width*(Math.sqrt(i)));case'sculpt':return Math.round(width*(Math.log((width-i-1),width)));case'dog':return(i&1)?(i+1):width;case'dog2':return(i&2)?(i+1):width;case'dog3':return(i&3)?(i+1):width;case'fray':return(i%2)*width;case'notch':return width;case'bevel':return i+1;}};$.fn.corner=function(o){if(this.length==0){if(!$.isReady&&this.selector){var s=this.selector,c=this.context;$(function(){$(s,c).corner(o);});}
return this;}
o=(o||"").toLowerCase();var keep=/keep/.test(o);var cc=((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);var sc=((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);var width=parseInt((o.match(/(\d+)px/)||[])[1])||10;var re=/round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;var fx=((o.match(re)||['round'])[0]);var edges={T:0,B:1};var opts={TL:/top|tl/.test(o),TR:/top|tr/.test(o),BL:/bottom|bl/.test(o),BR:/bottom|br/.test(o)};if(!opts.TL&&!opts.TR&&!opts.BL&&!opts.BR)
opts={TL:1,TR:1,BL:1,BR:1};var strip=document.createElement('div');strip.style.overflow='hidden';strip.style.height='1px';strip.style.backgroundColor=sc||'transparent';strip.style.borderStyle='solid';return this.each(function(index){var pad={T:parseInt($.css(this,'paddingTop'))||0,R:parseInt($.css(this,'paddingRight'))||0,B:parseInt($.css(this,'paddingBottom'))||0,L:parseInt($.css(this,'paddingLeft'))||0};if(typeof this.style.zoom!=undefined)this.style.zoom=1;if(!keep)this.style.border='none';strip.style.borderColor=cc||gpc(this.parentNode);var cssHeight=$.curCSS(this,'height');for(var j in edges){var bot=edges[j];if((bot&&(opts.BL||opts.BR))||(!bot&&(opts.TL||opts.TR))){strip.style.borderStyle='none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');var d=document.createElement('div');$(d).addClass('jquery-corner');var ds=d.style;bot?this.appendChild(d):this.insertBefore(d,this.firstChild);if(bot&&cssHeight!='auto'){if($.css(this,'position')=='static')
this.style.position='relative';ds.position='absolute';ds.bottom=ds.left=ds.padding=ds.margin='0';if(expr)
ds.setExpression('width','this.parentNode.offsetWidth');else
ds.width='100%';}
else if(!bot&&$.browser.msie){if($.css(this,'position')=='static')
this.style.position='relative';ds.position='absolute';ds.top=ds.left=ds.right=ds.padding=ds.margin='0';if(expr){var bw=sz(this,'borderLeftWidth')+sz(this,'borderRightWidth');ds.setExpression('width','this.parentNode.offsetWidth - '+bw+'+ "px"');}
else
ds.width='100%';}
else{ds.margin=!bot?'-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px':(pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';}
for(var i=0;i<width;i++){var w=Math.max(0,getWidth(fx,i,width));var e=strip.cloneNode(false);e.style.borderWidth='0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';bot?d.appendChild(e):d.insertBefore(e,d.firstChild);}}}});};$.fn.uncorner=function(){$('div.jquery-corner',this).remove();return this;};})(jQuery);

// jQuery csb (custom selectbox) plugin
// version 1.0
// Author Mihkel Oviir
(function($){
	
	$.fn.csb = function(options) {
		$(this).hide();

		var style = options.style;
		var mode = options.mode;

		var thisid = $(this).attr('id');
		var selected = this.find("option[selected]");

		if (mode == 'link') var selects = this.find("option:not([selected])");
		else var selects = this.find("option");
		$(this).parent().append('<dl id="'+thisid+'" class="'+style+'"></dl>');
		$('dl#'+thisid).append('<dt><a name="' + selected.val() + '">' + selected.text() + '</a></dt>');
		$('dl#'+thisid).append('<dd><ul></ul></dd>');
		selects.each(function(){
			$('dl#'+ thisid + " dd ul").append('<li><a name="' + $(this).val() + '">' + $(this).text() + '</a></li>');
		});

		$('.'+style+' dt a').click(function() {
			$('.'+style+' dd ul').toggle();
			return false;
		});

		$(document).bind('click', function(e) {
			var $clicked = $(e.target);
			if (! $clicked.parents().hasClass(style)) $('.'+style+' dd ul').hide();
		});

		if (mode == 'link') {
			$('.'+style+' dd ul li a').live('click',function() {
				$('.'+style+' dd ul').hide();
				var functvar = $(this).attr('name');
				
				// now call a callback function
				if(typeof options.callback == 'function'){
					options.callback(functvar);
				}
				return false;
			});
		}
		else {
			$('.'+style+' dd ul li a').live('click',function() {
				var text = $(this).html();
				$('.'+style+' dt a').html(text);
				$('.'+style+' dd ul').hide();

				var source = $('select#'+thisid);
				var functvar = $(this).attr('name');
				source.val(functvar);
				
				// now call a callback function
				if(typeof options.callback == 'function'){
					options.callback(functvar);
				}
				return false;
			});
		}	
	}
})(jQuery);


// Initialise Things
var menuColours = ['#4a56a2','#e32d43','#39bef7','#b0d32f','#d28533','#ff00c2', '#ffde00','#872c8b'];
var menuClasses = ['one','two','three','four','five','six','seven','eight'];


// home start here function
function onSelectMoodul(selected){
	$('.home-start').add('.home-start-text').fadeOut();
	$("#home-start-"+selected).fadeIn();			
}

jQuery(function(){
	if ($.cookie('style') != "textonly") {
		// initialise things if not text-only
		
		// we want even height boxes on the homepage
		$('#start_here_box .box_content').css('height',$('home_news_box .box_content').height()+"px");


		// if ie6 or less use this code for homepage select box
		if ($.browser.msie && parseInt($.browser.version)){
				$('#change').change( function(){
					onSelectMoodul($('#change option:selected').val());
				});
		} else {
			// initialise the pretty select box on homepage
			$('#change').csb({
				style: 'startdropdown',
				mode: 'select',
				callback: function(arg){
					onSelectMoodul(arg);
				}
			});
		}
	



		htmlClose = '<img src="/fileadmin/template/main/landdata-v2.0/img/menu_close.gif" width="12" height="11" alt="Expand Menu" />';
		htmlOpen = '<img src="/fileadmin/template/main/landdata-v2.0/img/menu_open.gif" width="12" height="11" alt="Expand Menu" />';
		// menu expand
		$('#sideMenu li.level2-act .expand_menu:eq(0)').html(htmlClose).removeClass("closed").addClass("open");
		$('#sideMenu li.level3-act .expand_menu:eq(0)').html(htmlClose).removeClass("closed").addClass("open");
		$('.expand_menu').click(function() {
			$(this).next().slideToggle("fast");
			if($(this).hasClass("closed")) {
				$(this).removeClass("closed").addClass("open");
				$(this).html(htmlClose);
			} else {
				$(this).removeClass("open").addClass("closed");
				$(this).html(htmlOpen);
			}
		});

		// menu corners
		$('#nav li.main a.toplevel').corner("7px");
		// menu colours
		$('#nav li.main').each(function(i) {
				$(this).addClass(menuClasses[i]);
		});

		// initialise drop down menu
		$("ul.sf-menu").superfish({
			speed : 1
		});

		// Login box open/close 
		$('#member_login #tx-newloginbox-pi1-login_submit').click(memberLoginSubmit);
		$("#member_login #bottom").click(function(){
		if( $('#member_login').hasClass('open') ){
			$("#member_login").animate({
				top: "-176px" //TODO should come down according to height of #member_login div
			}, 500, function(){
				//$("#member_login").css("z-index","600");
				//$("#menu_top ul.inline_menu").css("z-index","700");	
			$('#member_login').removeClass("open");
			});
			$("#member_login #login-arrow").attr("src","/fileadmin/template/main/landdata-v2.0/img/login-arrow-down.gif");
			return false;
		} else {
			$("#member_login").animate({top: "0px"}, 500, function(){
				$("#member_login #login-arrow").attr("src","/fileadmin/template/main/landdata-v2.0/img/login-arrow-up.gif");
				//$("#member_login").css("z-index","700");
				//$("#menu_top ul.inline_menu").css("z-index","600");

			});
			$('#member_login').addClass("open");
			return false;
		}
		});
	
		// Home Featured Widget
		// unhide featured news
		$('#home-featured').show();

		// Add custom classes to tabs
		$('#home-featured .featured-item:eq(0)').addClass('one');
		$('#home-featured .featured-item:eq(0) h3').addClass('active');
		$('#home-featured .featured-item:eq(0) .featured-item-image').addClass('activeImage');
		$('#home-featured .featured-item:eq(1)').addClass('two');
		$('#home-featured .featured-item:eq(2)').addClass('three');

		// create right image
		//alert($('#home-featured .featured-item:eq(0) .featured-item-image img').attr('src'));
		$('#home-featured').prepend('<a id="featured-link" href="'+$('#home-featured .featured-item:eq(0) h3 a').attr('href')+'"><img id="featured-image" src="'+$('#home-featured .featured-item:eq(0) .featured-item-image img').attr('src')+'" /></a>');

		// debug
		//alert($('#home-featured').html());

		// rollover for h3 / button
		$('#home-featured h3').mouseover( function(){
		  if( $(this).hasClass('active')) {
		    // do nothing
		  } else {
		    $('#home-featured h3').removeClass('active');
		    $(this).addClass('active');
		    $('#home-featured #featured-image').attr('src',$(this).next().find('img').attr('src'));
		    $('#home-featured #featured-link').attr('href',$(this).find('a').attr('href'));
		  }
		});
	}
});


// Member login
function memberLogin(button) {
	$(button).attr("onClick","");
	$('#member_login #top').load('/index.php?id=3087', function() {
		$('#member_login #top .tx-newloginbox-pi1-forgotP').hide();
		$('#member_login #tx-newloginbox-pi1-login_submit').click(memberLoginSubmit);
		$('#member_login #top').fadeIn('fast');
	});
	return false;
}

function memberLoginSubmit() {
	$('#member_login #top #tx-newloginbox-pi1-login_submit').replaceWith("<img src='/fileadmin/template/main/landdata-v2.0/img/mini-throbber.gif' /> Logging in");
	jname = $("#member_login #tx-newloginbox-pi1-user").val();
	jpass = $("#member_login #tx-newloginbox-pi1-pass").val();
	$.post('/index.php?id=3087',{
		user: jname,
		pass: jpass,
		pid: '2429,2595',
		redirect_url: '',
		submit: 'login',
		logintype: 'login'
		}, function(data) {
			$('#member_login #top').html(data);
			$('#member_login #top #tx-newloginbox-pi1-login_submit').click(memberLoginSubmit);
	}, "html");
	return false;
}


