/*
 * HWK Design Pattern Library
 * 
 * Beschreibung: jQuery Scripts
 * letztes Update: 10.06.2011
 * Version: 1.0.1
 * Autor: FUF // Frank und Freunde, www.fuf.de
 * 
 * */

/* Carousel config START */
function carousel_initCallback(carousel) {
	
	jQuery('.jcarousel-scroll').show();
	jQuery('.jcarousel-control span').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});
	jQuery('#carousel-next').bind('click', function() {
		carousel.next();
		return false;
	});
	jQuery('#carousel-prev').bind('click', function() {
		carousel.prev();
		return false;
	});
};
/* Carousel config END */
/* Font-resize config START */
function makeFontBigger() {
	jQuery("h1").css('font-size', '19px');
	jQuery("h2").css('font-size', '17px');
	jQuery("h4, p, ul a, ul, ol a, ol, .sidebarRight a, .level1, .breadcrumb, .metaNavi, .table a, label, .checkRadiobreadcrumb, .metaNavi span, .form textarea, .errorNote").not('#carousel, .jcarousel-clip, .jcarousel-clip-horizontal, .jcarousel-scroll, .jcarousel-list, .jcarousel-list-horizontal, .jcarousel-item').css('font-size', '14px'); 
	jQuery(".headItems").css('font-size', '13px');
	jQuery(".fontBigger").css('text-decoration', 'underline');
	//set the cookie
	jQuery.cookie('hwkFontResize', 'bigger');
};
function makeFontNormal() {
	jQuery(".fontBigger, h1, h2, h4, p, ul a, ul, ol a, ol, .sidebarRight a, .level1, .breadcrumb, .metaNavi, .table a, label, .checkRadiobreadcrumb, .metaNavi span, .form textarea, .errorNote, .headItems").not('#carousel, .jcarousel-clip, .jcarousel-clip-horizontal, .jcarousel-scroll, .jcarousel-list, .jcarousel-list-horizontal, .jcarousel-item').removeAttr('style');
	//reset the cookie
	jQuery.cookie('hwkFontResize', 'normal');
};
/* Font-resize config END */
/* Slimbox2: AUTOLOAD CODE BLOCK */
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	jQuery(function($) {
		$("a[rel^='lightbox']").slimbox({
			/* Put custom options here */
			counterText: "Bild {x} von {y}",
			nextKeys: [39, 87],
			previousKeys: [37, 90]
			}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	});
}
/* document ready */
jQuery(document).ready(function() {
	/* Carousel START */
	jQuery("#carousel").jcarousel({
		scroll: 1,
		wrap: 'circular',
		initCallback: carousel_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	/* Carousel END */
	/* Font-resize START */
	// check cookie value
	if (jQuery.cookie('hwkFontResize') == 'bigger') {
		makeFontBigger();
	}
	;
	// click-event: bigger font-size
	jQuery(".fontBigger").click(function() {
		makeFontBigger()
	});
	// click-event: normal font-size
	jQuery(".fontNormal").click(function() {
		makeFontNormal()
	});
	/* Font-resize END */
});

/** ODAV Leftmenu START **/
function selectMenu(onr, pnr, mnr) {
	var $allMenid = jQuery(".sidebarLeft .subNavi.box .body").filter(":visible").find("a[data-meiid]");
	var menuItemFound = false;
	if ($allMenid.length > 0) {
		if (mnr > 0) {
			$allMenid.each(function(index) {
				var $this = jQuery(this);
				if ($this.data('meiid') == mnr) {
					menuItemFound = true;
					showItems($this);
					return false;
				}
			});
		}
		if (!menuItemFound) {
			var hasQueryString = (location.search!='');
			var testString = "," + pnr + ".html" + (hasQueryString ? location.search : "");
			menuItemFound = searchForPnrString($allMenid, testString);
			if (hasQueryString && !menuItemFound) {
				testString =  "," + pnr + ".html";
				menuItemFound = searchForPnrString($allMenid, testString);
			}
		}
	}
}

function searchForPnrString(allMenid, testString) {
	var menuItemFound = false;
	allMenid.each(function(index) {
		var $this = jQuery(this);
		var href = $this.attr('href');
		if (href && href.indexOf(testString) != -1) {
			menuItemFound = true;
			showItems($this);
			return false;
		}
	});
	return menuItemFound;
}

function showItems($item) {
	if ($item.length > 0) {
		$item.addClass('active').siblings('ul').css('height', 'auto').show();
		var $parent = $item.parent().parent();
		var level = $parent.data('level');
		switch (level) {
		case 3:
			$parent.css('height', 'auto').show().siblings().addClass('active');
			break;
		case 4:
			$parent.css('height', 'auto').show().siblings().addClass('active');
			$parent.parent().parent().css('height', 'auto').show().siblings().addClass('active');
			break;
		case 5:
			$parent.css('height', 'auto').show().siblings().addClass('active');
			$parent.parent().parent().css('height', 'auto').show().siblings().addClass('active');
			$parent.parent().parent().parent().parent().css('height','auto').show().siblings().addClass('active');
			break;
		}
		jQuery('.active').last().addClass('current').removeClass('active');
	}
}
/** ODAV Leftmenu END **/
