/*
 * jQuery resize event - v1.1 - 3/14/2010
 * http://benalman.com/projects/jquery-resize-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);

/**
 * Description: Customized JavaScript Document for jQueryPlugins.
 * Version: 1.0
 * Author: Peter Rozek
 * Author URI: http://www.ecomplexx.com
 * Tags: lovelife
*/


/** 
 * @version			1.0
 * @lastmodified	$Date: 2010-10-01 10:26:40 +0200 (fr,  Oktober 2010)$
 * @type			all Stylesheet
*/
// drop your customized JavaScript in ths document
		
	function extCall(event, ident){
		document.getElementById(ident).sendEvent(event);
	}
	
// JavaScript jQuery
jQuery(document).ready(function($){
	
	$('.fontsizer > span').click(function(){
		changeSize = 2;
		nowSize = $('body').css('font-size');
	
		if($(this).attr('id') == 'addSize')
		{
			$('body').css('font-size', parseFloat(nowSize.replace('px', '')) + changeSize + 'px');
		}
		else
		{
			$('body').css('font-size', parseFloat(nowSize.replace('px', '')) - changeSize + 'px');
		}
	});
	


	// recaptcha challenge switcher
	$('.captcha_challenge').click(function(){
		if($(this).attr('id') == 'captcha_image')
		{
			$(this).css('color', '#000000');
			$(this).css('text-decoration', 'underline');
			$('#captcha_audio').css('color', '#D24684');
			$('#captcha_audio').css('text-decoration', 'none');
			Recaptcha.switch_type('image');
		}
		else
		{
			$(this).css('color', '#000000');
			$(this).css('text-decoration', 'underline');
			$('#captcha_image').css('color', '#D24684');
			$('#captcha_image').css('text-decoration', 'none');
			Recaptcha.switch_type('audio');
		}
	});

	if($('.twocolumns').html() != null){
		maxElem = 10;
		elemCount = $('.twocolumns > .content > li').size();
		if(elemCount >= maxElem){
			maxElem = Math.round(elemCount/2);
		}
		
		
	}else if($('#flash-slides').html() != null)
	{
		maxElem = 8;
		elemCount = $('#paging_container > .content > li').size();
	}
	else if($('.paginategauto').html() != null)
	{
		maxElem = 10;
		elemCount = $('#paging_container > .content > li').size();
		if(elemCount >= maxElem){
			maxElem = Math.round(elemCount/2);
		}
	}
	else{
		maxElem = 4;
		elemCount = $('#paging_container > .content > li').size();
	}

	if(elemCount > maxElem){

		// Pagination
		$('#paging_container').pajinate({
			items_per_page : maxElem,
			nav_label_first : '',
			nav_label_last : '',
			nav_label_prev : '<',
			nav_label_next : '>'
		});
	 
	}
 
	//$("#main-navigation").sortable();
	
	$('#main-navigation').prepend($('.ui-state-highlight'));
	
	// jQuery ScrollPane
	$('.scroll-pane').jScrollPane({
		showArrows: true,
		hijackInternalLinks: true,
		hijackExternalLinks: true
	});
	
	
});


// role attribute workaround
function setRoleAttribute(id, rolevalue) {
	if(document.getElementById(id)) {
		document.getElementById(id).setAttribute("role", rolevalue);
	}
}
function setAriaRoleElementsById() {
	setRoleAttribute("header", "banner");
	setRoleAttribute("mainnav", "navigation");
	setRoleAttribute("footer", "contentinfo");
	setRoleAttribute("language", "navigation");
	setRoleAttribute("content", "main");
}
window.onload = function(){ setAriaRoleElementsById(); }


 $(document).ready(function() {
 
 
	function showShopBorder(){
		if($('.shopwrapper').length > 0){
			$('.border').css('display', 'block');
		}
	}
	
	showShopBorder();
 
 
	 function campaignpic(){

		border_right = 50;
		border_bottom = 55;
	 
		containerheight = $('.jspContainer').height();
		containerwidth = $('.jspContainer').width()-border_right;

		maxheight = containerheight-border_bottom;
		
		$('div.campaign > img').each(function(){
		
			imgurl = $(this).attr('src');
		
			var img = new Image();
			img.src = imgurl;
			
			format = img.height/img.width;

			newwidth = containerwidth;
			newheight = newwidth*format;

			if(newheight > maxheight){
				//$(this).attr('width', maxheight/format);
				if(maxheight > 0){
					$(this).attr('height', maxheight);
				}else{
					$(this).attr('height', '150');
				}				
			}else{
				//$(this).attr('width', newwidth);
				if(newheight > 0){
					$(this).attr('height', newheight);
				}else{
					$(this).attr('height', '150');
				}
			}		
		});
	}
	
	campaignpic();
	
	
	var rtime = new Date(1, 1, 2000, 12,00,00);
	var timeout = false;
	var delta = 100;
	
	jQuery(window).bind( 'resize', function() {
		rtime = new Date();
		if (timeout === false) {
			timeout = true;
			setTimeout(resizeend, delta);
		}
	});
	
	
	
	function resizeend() {
		if (new Date() - rtime < delta) {
			setTimeout(resizeend, delta);
		} else {
			timeout = false;
			$('.scroll-pane').jScrollPane({
				showArrows: true,
				hijackInternalLinks: true,
				hijackExternalLinks: true
			});
			campaignpic();
		}				
	}
	
	if ($.browser.mozilla){
		$(document).keypress (function(event) {

			if(document.getElementById('limesurvey') != null){
				if (event.which == '13') {
					//alert('press enter');
					if(document.limesurvey.move.value == 'movenext'){
						document.limesurvey.move.value = 'movenext';
					}else{
						document.limesurvey.move.value = 'movesubmit';
					}
					
					$('#limesurvey').submit();
				}
			}
		});
	}else {
		$(document).keydown (function(event) {

			if(document.getElementById('limesurvey') != null){
				if (event.which == '13') {
					//alert('press enter');
					if(document.limesurvey.move.value == 'movenext'){
						document.limesurvey.move.value = 'movenext';
					}else{
						document.limesurvey.move.value = 'movesubmit';
					}
					$('#limesurvey').submit();
				}
			}
		});
	}
 
 
	function contentHeight(){
	
		contentHeight = $('.jspPane').height();
		
		if(contentHeight > '333'){
		
			navHeight = $('#main-navigation').height();
			$('#content').css('height', navHeight+'px');
			$('#content > .main').css('height', navHeight+'px');
			$('.scroll-pane').css('height', (navHeight-40)+'px');
			
			$('.scroll-pane').jScrollPane({
				showArrows: true,
				hijackInternalLinks: true,
				hijackExternalLinks: true
			});
		}
		
	}
	
	if($('#content').html() != null && $('.campaign').html() == null && $('.shop').html() == null){
		contentHeight();
	}
	
 
 });


