/*

------------------------------------------------------ */
$().ready(function () {

	// add class for bloglist on experts
	$('.expertBlog .blog:nth-child(3n+1)').addClass('clearLeft');

	//Remove line from linked images
	$('a img').closest('a').css('border', 'none');

	// custom checkbox for "Change business area"
	$('.fanzy').each(function () {
		$(this).find('input[type=checkbox]').wrap(function () {
			return ($(this).is(':checked')) ? '<div class="custom_checkbox selected" />' : '<div class="custom_checkbox" />';
		});
	});
	$('.custom_checkbox').click(function () {
		var tmpCheck = $(this).find('input[type=checkbox]');
		if ($(tmpCheck).is(':checked')) {
			$(tmpCheck).attr('checked', false);
			$(this).addClass('selected');
		} else {
			$(tmpCheck).attr('checked', true);
			$(this).removeClass('selected');
		}
		$(this).toggleClass('selected');
	});

	// fixing the footer for smaller screens, only for IE, other browsers changed by css... 
	var winHeight = $(window).height();
	if (winHeight < '600' && $.browser.msie) {
		$('#footer').css('position', 'relative');
	}

	// adding random-squares for banner
	// if body class = software or group add a random 
	var random = Math.floor(Math.random() * 8);
	var className = "random" + random;
	$("body.software").find(".squares").addClass(className);
	$("body.group").find(".squares").addClass(className);
	$("body.experts").find(".squares").addClass(className);

	// initialize scrollable - old
	$(".scrollable").find(".banner:first").addClass("firstPanel");
	$(".scrollable").scrollable({ autoplay: true, circular: true }).autoscroll({ speed: 1200, interval: 10000 }).navigator();

	// fixing the alingment of the naviagtion in scrollable
	var tmpMargin = '-' + $(".navi").innerWidth() / 2 + 'px';
	$(".navi").css("margin-left", tmpMargin);

	// open business area
	$(".show_lang").colorbox({
		width: '820px',
		inline: true,
		overlayClose: false,
		scrolling: false,
		href: '.langForm',
		onClosed: function () { closingColorbox(); }
	});

	// open login
	$(".show_login").colorbox({
		width: '600px',
		inline: true,
		overlayClose: false,
		scrolling: false,
		href: '.userForm',
		onComplete: function () {
			$.colorbox.resize();
		},
		onClosed: function () { closingColorbox(); }
	});

	// open dialog for extra data
	$(".show_extra_data").colorbox({
		width: '600px',
		inline: true,
		overlayClose: false,
		scrolling: false,
		href: '.userForm',
		onComplete: function () {
			// alert("show extra data");
			$(".userForm").find(".userLogin").hide('fast');
			$(".userForm").find(".userRegister").hide('fast');
			$(".userForm").find(".userForgottPassword").hide('fast');
			$(".userForm").find(".userExtradata").show('fast');
			$.colorbox.resize();
		},
		onClosed: function () { closingColorbox(); }
	});

	// open dialog for password reminder
	$(".show_password_reminder").colorbox({
		width: '600px',
		inline: true,
		overlayClose: false,
		scrolling: false,
		href: '.userForm',
		onComplete: function () {
			// alert("show password reminder");
			$(".userForm").find(".userLogin").hide('fast');
			$(".userForm").find(".userRegister").hide('fast');
			$(".userForm").find(".userExtradata").hide('fast');
			$(".userForm").find(".userForgottPassword").show('fast');
			$.colorbox.resize();
		},
		onClosed: function () { closingColorbox(); }
	});

	// open dialog for new user
	$(".show_new_user").colorbox({
		width: '600px',
		inline: true,
		overlayClose: false,
		scrolling: false,
		href: '.userForm',
		onComplete: function () {
			//			alert("show new user");
			$(".userForm").find(".userLogin").hide('fast');
			$(".userForm").find(".userForgottPassword").hide('fast');
			$(".userForm").find(".userExtradata").hide('fast');
			$(".userForm").find(".userRegister").show(100, function () {
				$.colorbox.resize();
			});
		},
		onClosed: function () { closingColorbox(); }
	});

	// forgot password
	$('.forgottPassword').click(function (e) {
		e.preventDefault();
		// alert("password");
		$(".userForm").find(".userLogin").hide('fast');
		$(".userForm").find(".userRegister").hide('fast');
		$(".userForm").find(".userExtradata").hide('fast');
		$('.userForm').find('.userForgottPassword').show(100, function () {
			$.colorbox.resize();
		});
	});

	// show form for register new user
	$('.newUser').click(function (e) {
		e.preventDefault();
		// alert("new user");
		$(".userForm").find(".userLogin").hide('fast');
		$(".userForm").find(".userForgottPassword").hide('fast');
		$(".userForm").find(".userExtradata").hide('fast');
		$('.userForm').find('.userRegister').show(100, function () {
			$.colorbox.resize();
		});
	});

	// show form for login
	$('.loginUser').click(function (e) {
		e.preventDefault();
		// alert("login user");
		$(".userForm").find(".userRegister").hide('fast');
		$(".userForm").find(".userForgottPassword").hide('fast');
		$(".userForm").find(".userExtradata").hide('fast');
		$('.userForm').find('.userLogin').show(100, function () {
			$.colorbox.resize();
		});
	});

	// infinite scroll for search result, no plugin is used
//	function lastAddedLiveFunc() {
//		$('div.loading').show();
//		$.post($('.url-for-search-result').val(),
//		function (data) {
//			if (data != "") {
//				$(".search-result:last").append(data);
//			} else {
//				$('div.loading').hide();
//			}
//		});

//	};
//	$(window).scroll(function () {
//		if ($(window).scrollTop() == $(document).height() - $(window).height()) {
//			lastAddedLiveFunc();
//		}
//	});

	// expand and collapse of training... 
	var toggle = true;
	$("h2.training").click(function () {
		$(this).parent().parent().toggleClass("open");
		var theID = $(this).next('ul');
		$(theID).toggleClass("open");
		$(theID).find('ul').toggleClass("open");
	});

	// fixing styling issues for IE8 and below... the divs is to be included in the demplates by default. 
	if ($.browser.msie && $.browser.version < 9) {
		$('body').addClass('ie');
		$('.banner .text-right').append('<div class="ie-top"></div>');
	}

	// fixing the navigation in scrollable for start page... 
	if ($('.banner.columns').length) {
		$('#banner').addClass('startpage');
	}

	// click banner
	$(".box.prod").click(function () {
		var theLink = $(this).find("a").attr("href");
		if (theLink) {
			window.location = theLink;
			return true;
		}
		return false;
	});

	// click banner
	//	$("#hubs").click(function () {
	//		var theLink = $(this).find("a").attr("href");
	//		if (theLink) {
	//			window.location = theLink;
	//			return true;
	//		}
	//		return false;
	//	});

});
function closingColorbox() {
// NOT IN USE? causes errors when closing other forms... 
//	$(".userForm").find(".userLogin").hide();
//	$(".userForm").find(".userForgottPassword").hide();
//	$(".userForm").find(".userExtradata").hide();
//	$(".userForm").find(".userRegister").hide();
}
