jQuery(function() {
	jQuery(window).resize(function() {
		var height = jQuery(window).height() < 760 ? 760 : jQuery(window).height();
		jQuery('.siteContainer').height(height);
		jQuery('.homeBackground').height(height);
	}).resize();
});

function InitBackground() {
	jQuery(window).resize(function() {
		var	height = jQuery(window).height() < 780 ? 780 : jQuery(window).height(),
			width = jQuery(window).width() < 1016 ? 1016 : jQuery(window).width(),
			bg = jQuery('.backgroundContainer'),
			img = bg.find('img'),
			cst = width / img.width();
		
		if(img.height() * cst < height) {
			cst = height / img.height();
		}
		
		bg.width(width).height(height);
		img.width(img.width() * cst).height(img.height() * cst);
	}).resize();
}

function InitBackgroundConstrain() {
	jQuery(window).resize(function() {
		var	height = jQuery(window).height() < 780 ? 780 : jQuery(window).height(),
			width = jQuery(window).width() < 1016 ? 1016 : jQuery(window).width(),
			bg = jQuery('.backgroundContainer'),
			img = bg.find('img'),
			cst = width / img.width();

		if(img.height() * cst < height) {
			cst = height / img.height();
		}
		
		bg.width(width).height(height);
		img.width(img.width() * cst).height(img.height() * cst);
	}).resize();
}

function InitHeader() {
	jQuery.easing.def = "easeInOutSine";
	var	siteContainer = jQuery('.siteContainer'),
		headerWrapper = jQuery('.headerWrapper'),
		header = headerWrapper.find('.header'),
		big = headerWrapper.find('.bigContainer').css('opacity', 0),
		small = headerWrapper.find('.logoWrapper'),
		nav = headerWrapper.find('.navigation a'),
		navWrapper = nav.parents('.navigation'),
		productsItems = jQuery('.productsMenuWrapper, .productsViewportWrapper, .flashViewport'),
		headeranimation = false,
		adjustWidth = function() {
			header.css({
				height: 304,
				left: 244 - header.width(),
				top: -19
			});
			big.css({
				opacity: 0,
				width: siteContainer.width()
			});
			navWrapper.css({
				display: 'block'
			});
			productsItems.css('z-index', 150);
		};
	
	/* DEBUG ONLY */
	/*header.css({
		left: -(header.width() - siteContainer.width() - 250),
		top: -126
	});
	big.css({
		opacity: 1,
		width: siteContainer.width()
	});
	navWrapper.css({
		display: 'none'
	});
	return;*/
	/* END DEBUG */
	
	nav.click(function(e) {
		e.preventDefault();
		
		if(headeranimation == false) {
			headeranimation = true;
			header.stopTime('headeranimation').stop().animate({
				height: 371,
				left: -(header.width() - siteContainer.width() - 250),
				top: -126
			}, 400, function () {
				headeranimation = false;
				big.css({
					opacity: 1,
					width: siteContainer.width()
				});
			});
			navWrapper.css({
				display: 'none'
			});
			productsItems.css('z-index', 50);
		}
	});
	
	headerWrapper.mouseleave(function() {
		if(headeranimation == true) {
			headeranimation = false;
			header.stop().animate({
				height: 304,
				left: 244 - header.width(),
				top: -19
			}, 150, function() {
				productsItems.css('z-index', 150);
			});
			big.css({
				opacity: 0
			});
			navWrapper.css({
				display: 'block'
			});
		} else {
			header.oneTime('2s', 'headeranimation', function() {
				header.stop().animate({
					height: 304,
					left: 244 - header.width(),
					top: -19
				}, 250, function() {					
					navWrapper.css({
						display: 'block'
					});
					productsItems.css('z-index', 150);
				});
				big.css({
					opacity: 0
				});
			});
		}
	}).mouseenter(function() {
		header.stopTime('headeranimation');
	});
	
	jQuery(window).resize(adjustWidth);
}

function InitMenu() {
	var	menuItems = jQuery('li.menuItem');
	
	jQuery.each(menuItems, function(index, item) {
		jQuery(item).width(jQuery(item).find('.menuItemWrapper a').outerWidth() + 16);
		
		if(!jQuery(item).hasClass('selected')) {
			jQuery(item).hover(
				function() {
					jQuery(item).addClass('selected');
				},
				function() {
					jQuery(item).removeClass('selected');
				}
			).mousedown(function() {
				jQuery(item).addClass('click');
			}).mouseup(function() {
				jQuery(item).removeClass('click');
			});
		} else {
			jQuery(item).mousedown(function() {
				jQuery(item).removeClass('selected').addClass('click');
			}).mouseup(function() {
				jQuery(item).removeClass('click').addClass('selected');
			});
		}
		
		jQuery(item).hover(
			function() {
				jQuery(jQuery('.submenuWrapper').get(index)).css('display', 'block');
				jQuery('.submenuWrapper').not(jQuery(jQuery('.submenuWrapper').get(index))).css('display', 'none');
			},
			function() {
				/*jQuery(jQuery('.submenuWrapper').get(index)).css('display', 'none');*/
			}
		);
		
		var	submenuWrapper = jQuery(jQuery('.submenuWrapper').get(index)),
			submenuItems = submenuWrapper.find('li.submenuItem'),
			topItem = false;
		
		if(submenuWrapper.find('ul').size() > 0) {
			submenuWrapper.css({
				opacity: 0,
				display: 'block'
			}).hover(
				function() {
					if(!jQuery(item).hasClass('selected')) {
						topItem = true;
						jQuery(item).addClass('selected');
					}
					submenuWrapper.css('display', 'block');
				},
				function() {
					if(topItem) {
						topItem = false;
						jQuery(item).removeClass('selected');
					}
					submenuWrapper.css('display', 'none');
				}
			);
		}
		
		jQuery.each(submenuItems, function(index, item) {	
			if(!jQuery(item).hasClass('selected')) {
				jQuery(item).hover(
					function() {
						jQuery(item).addClass('selected');
					},
					function() {
						jQuery(item).removeClass('selected');
					}
				).mousedown(function() {
					jQuery(item).addClass('click');
				}).mouseup(function() {
					jQuery(item).removeClass('click');
				});
			} else {
				jQuery(item).mousedown(function() {
					jQuery(item).removeClass('selected').addClass('click');
				}).mouseup(function() {
					jQuery(item).removeClass('click').addClass('selected');
				});
			}
		});
		
		submenuWrapper.css({
			opacity: 1,
			display: 'none'
		});
	});
}

function InitLanguage() {
	jQuery('.languageWrapper .dropdown').css('opacity', 0);
	
	jQuery('.languageWrapper').mouseenter(function(e) {
		//e.preventDefault();
		
		jQuery('.languageWrapper .dropdown').stop().animate({
			height: jQuery('.languageWrapper .dropdown ul').outerHeight(),
			opacity: 1
		}, 200);
	});
	
	jQuery('.languageWrapper').mouseleave(function() {
		jQuery('.languageWrapper .dropdown').stop().animate({
			height: 0,
			opacity: 0
		}, 50);
	});
}

function InitHomepage() {
	var	siteContainer = jQuery('.siteContainer'),
		imgContainer = jQuery('.homeBackground'),
		hlLeft = jQuery('.homeContent .highlightLeft').css('opacity', 0).css('cursor', 'pointer'),
		hlRight = jQuery('.homeContent .highlightRight').css('opacity', 0).css('cursor', 'pointer'),
		el = jQuery('.homeContent'),
		img = imgContainer.find('img'),
		baseWidth = img.attr('width'),
		baseHeight = img.attr('height'),
		adjustWidth = function() {
			el.height(siteContainer.height() - 35);
			img.width(imgContainer.width() + 600);
			img.height((img.width() / baseWidth) * baseHeight);
			center = imgContainer.width() / 2;
			img.css({
				left: center - (img.width() / 2),
				top: (imgContainer.height() / 2) - (img.height() / 2)
			});
			hlRight.width(hlRight.find('.textWrapper').width()).css({
				opacity: 1,
				left: center + offset
			});
			hlLeft.width(hlLeft.find('.textWrapper').width()).css({
				opacity: 1,
				left: center - hlLeft.width() - offset
			});
			hlLeft.find('.textToggler').height(0);
			hlRight.find('.textToggler').height(0);
		},
		moveCenter = function() {
			el.stopTime('movecenter').oneTime('3s', 'movecenter', function() {
				hlCenterAnimation();
				animate = true;
				movedir = 'center';
				img.stop().animate({
					left: center - (img.width() / 2)
				}, timer, function() {
					animate = false;
				});
				leftOffset = center - offset;
				rightOffset = center + offset;
			});
		},
		moveLeft = function() {
			animate = true;
			movedir = 'left';
			img.stop().animate({
				left: center - (img.width() / 2) - movedist
			}, timer, function() {
				animate = false;
			});
			leftOffset = center - movedist;
		},
		moveRight = function() {
			animate = true;
			movedir = 'right';
			img.stop().animate({
				left:  center - (img.width() / 2) + movedist
			}, timer, function() {
				animate = false;
			});
			rightOffset = center + movedist;
		},
		hlLeftAnimation = function() {
			hlRight.stop().animate({
				opacity: 1,
				left: center + offset - movedist
			}, timer);
			hlRight.find('.textToggler').stop().animate({
				height: hlRight.find('.textWrapper').height(),
				opacity: 1
			}, timer / 2);
			hlRight.find('img').stop().animate({
				'padding-left': hlRight.find('img').data('padding-on')
			}, timer / 2);
			
			hlLeft.stop().animate({
				opacity: 0,
				left: center - hlLeft.width() - offset - movedist
			}, timer);
			hlLeft.find('.textToggler').stop().animate({
				height: 0,
				opacity: 0
			}, timer / 2);
			hlLeft.find('.linkWrapper').stop().animate({
				'padding-right': hlLeft.find('.linkWrapper').data('padding-off')
			}, timer / 2);
		},
		hlRightAnimation = function() {
			hlRight.stop().animate({
				opacity: 0,
				left: center + offset + movedist
			}, timer);
			hlRight.find('.textToggler').stop().animate({
				height: 0,
				opacity: 0
			}, timer / 2);
			hlRight.find('img').stop().animate({
				'padding-left': hlRight.find('img').data('padding-off')
			}, timer / 2);
			
			hlLeft.stop().animate({
				opacity: 1,
				left: center - hlLeft.width() - offset + movedist
			}, timer);
			hlLeft.find('.textToggler').stop().animate({
				height: hlLeft.find('.textWrapper').height(),
				opacity: 1
			}, timer / 2);
			hlLeft.find('.linkWrapper').stop().animate({
				'padding-right': hlLeft.find('.linkWrapper').data('padding-on')
			}, timer / 2);
		},
		hlCenterAnimation = function() {
			hlRight.stop().animate({
				opacity: 1,
				left: center + offset
			}, timer);
			hlRight.find('.textToggler').stop().animate({
				height: 0,
				opacity: 0
			}, timer / 2);
			hlRight.find('img').stop().animate({
				'padding-left': hlRight.find('img').data('padding-off')
			}, timer / 2);
			
			hlLeft.stop().animate({
				opacity: 1,
				left: center - hlLeft.width() - offset
			}, timer);
			hlLeft.find('.textToggler').stop().animate({
				height: 0,
				opacity: 0
			}, timer / 2);
			hlLeft.find('.linkWrapper').stop().animate({
				'padding-right': hlLeft.find('.linkWrapper').data('padding-off')
			}, timer / 2);
		},
		ratio = img.width() / img.height(),
		center = imgContainer.width() / 2,
		offset = 50,
		leftOffset = center - offset,
		rightOffset = center + offset,
		movedir = 'none',
		movedist = 300,
		animate = false,
		timer = 400,
		padder = 0;
	
	img.width((imgContainer.width() * 1.5));
	img.height((imgContainer.width() * 1.5) / ratio);
	
	img.css({
		left: center - (img.width() / 2),
		top: (imgContainer.height() / 2) - (img.height() / 2)
	});
	
	hlLeft.css({
		left: center - hlLeft.width() - offset
	});
	
	hlRight.css({
		left: center + offset
	});
	
	hlLeft.click(function() {
		window.location = jQuery(this).find('a').attr('href');
	});
	
	hlRight.click(function() {
		window.location = jQuery(this).find('a').attr('href');
	});
	
	hlLeft.find('.linkWrapper').hover(
		function() {
			jQuery(this).find('.left').css('background-position', 'left -38px');
			jQuery(this).find('.right').css('background-position', 'right -57px');
			jQuery(this).find('.inner').css('background-color', 'white');
			jQuery(this).find('a').css('color', 'black');
		},
		function() {
			jQuery(this).find('.left').css('background-position', 'left -76px');
			jQuery(this).find('.right').css('background-position', 'right -95px');
			jQuery(this).find('.inner').css('background-color', '#1e1e1e');
			jQuery(this).find('a').css('color', 'white');
		}
	);
	
	hlRight.find('.linkWrapper').hover(
		function() {
			jQuery(this).find('.left').css('background-position', 'left -38px');
			jQuery(this).find('.right').css('background-position', 'right -57px');
			jQuery(this).find('.inner').css('background-color', 'white');
			jQuery(this).find('a').css('color', 'black');
			
		},
		function() {
			jQuery(this).find('.left').css('background-position', 'left 0');
			jQuery(this).find('.right').css('background-position', 'right -19px');
			jQuery(this).find('.inner').css('background-color', '#d01f0f');
			jQuery(this).find('a').css('color', 'white');
		}
	);
	
	jQuery.each(hlLeft.find('img, p, .linkWrapper'), function(index, item) {
		if(index == 0) padder = 0;
		jQuery(item).css('padding-right', padder + 'px');
		
		if(index == (hlRight.find('img, p, .linkWrapper').size() - 1)) {
			jQuery(item).data('padding-on', padder).data('padding-off', (3 * (hlRight.find('img, p, .linkWrapper').size() - 1))).css('padding-right', jQuery(item).data('padding-off') + 'px');
		}
		
		if(index == 0) padder += 3 * (hlRight.find('img, p, .linkWrapper').size() - 1);
		else				padder += 3;
	});
	
	jQuery.each(hlRight.find('img, p, .linkWrapper'), function(index, item) {
		if(index == 0) padder = 3 * (hlRight.find('img, p, .linkWrapper').size() - 1);
		jQuery(item).css('padding-left', padder + 'px');
		
		if(index == 0) {
			jQuery(item).data('padding-on', padder).data('padding-off', '3').css('padding-left', jQuery(item).data('padding-off') + 'px');
		}
		
		padder -= 3;
	});
	
	jQuery(window).resize(adjustWidth).oneTime('10ms', function() {
		jQuery(this).resize();
		el.mousemove(function(e) {
			var	x = e.pageX;
			//console.log(x);
			if(x < leftOffset && movedir != 'right' && !animate) {
				moveRight();
				hlRightAnimation();
			}
				
			if(x > rightOffset && movedir != 'left' && !animate) {
				moveLeft();
				hlLeftAnimation();
			}
			moveCenter();
		});
	});
}

function InitProductMenu() {
	var totalHeight = 0;
	jQuery('.productsMenu li.selected').find('.off, .hover').css('display', 'none');
	
	jQuery('.productsMenu li').not('.productsMenu li.selected').find('.on, .hover').css('display', 'none');
	
	jQuery('.productsMenu li').not('.productsMenu li.selected').find('a').hover(
		function() {
			jQuery(this).find('.on').css('display', 'none');
			jQuery(this).find('.hover').css('display', 'block');
			jQuery(this).find('.off').css('display', 'none');
		},
		function() {
			jQuery(this).find('.on').css('display', 'none');
			jQuery(this).find('.hover').css('display', 'none');
			jQuery(this).find('.off').css('display', 'block');
		}
	);
	
	jQuery.each(jQuery('.productsMenu li'), function() {
		totalHeight += jQuery(this).height();
	});
	
	jQuery('.productsMenu').height(totalHeight + parseInt(jQuery('.productsMenu li:last').css('top')));
	
	jQuery(window).resize(function() {
		var	top = (jQuery('.siteContainer').height() - jQuery('.productsMenu').height() - 35) / 2;
		if(top < 22) top = 22;
		jQuery('.productsMenuWrapper').css({
			top: top
		})
	}).resize();
}

function InitProductViewport() {
	jQuery(window).resize(function() {
		var	site = jQuery('.siteContainer'),
			pvwrapper = jQuery('.productsViewportWrapper'),
			wrapper = pvwrapper.find('.wrapper'),
			viewportWrapper = jQuery('.viewportWrapper'),
			imgs = viewportWrapper.find('img');
		
		pvwrapper.width(site.width() - 61 - 268);
		pvwrapper.height(site.height() - 54 < 726 ? 726 : site.height() - 54);
		wrapper.width(pvwrapper.width()).height(pvwrapper.height());
		viewportWrapper.height(pvwrapper.height() - 216 < 496 ? 496 : pvwrapper.height() - 216),
		maxHeight = viewportWrapper.height() - 25;
		
		jQuery.each(imgs, function(index, item) {
			var	jitem = jQuery(item),
					ratio = 1;
			if(jitem.height() > maxHeight) {
				ratio = (maxHeight / jitem.height());
			} else if(jitem.width() > viewportWrapper.width()) {
				ratio = (viewportWrapper.width() / jitem.width());
			}
			jitem.css({
				height: jitem.height() * ratio,
				width: jitem.width() * ratio,
				left: (wrapper.width() / 2) - (jQuery(item).width() / 2)
			});
		});
	}).resize();
	
	var	pvw = jQuery('.productsViewportWrapper'),
		leftArrow = pvw.find('.leftArrow'),
		rightArrow = pvw.find('.rightArrow'),
		imgs = pvw.find('.viewportWrapper img').css({
			display: 'block',
			opacity: 0
		}),
		infoButton = jQuery('.infoWrapper .info .infoButton'),
		index = -1;
			
	if(imgs.size() <= 1) {
		leftArrow.css('display', 'none');
		rightArrow.css('display', 'none');
	}
	
	leftArrow.find('a').click(function(e) {
		e.preventDefault();
		index--;
		if(index < 0) index = imgs.size() - 1;
		
		imgs.not(jQuery(imgs.get(index)).stop().animate({
			opacity: 1
		}, 700)).stop().animate({
			opacity: 0
		}, 300);
	});
	
	rightArrow.find('a').click(function(e) {
		e.preventDefault();
		index++;
		if(index > imgs.size() - 1) index = 0;
		
		imgs.not(jQuery(imgs.get(index)).stop().animate({
			opacity: 1
		}, 700)).stop().animate({
			opacity: 0
		}, 300);
	}).click();
	
	infoButton.hover(
		function() {
			if(jQuery(this).hasClass('dark')) {
				jQuery(this).css('background-position', 'left -16px');
			} else {
				jQuery(this).css('background-position', 'left -48px');
			}
			jQuery(this).find('table').css('display', 'block');
		},
		function() {
			if(jQuery(this).hasClass('dark')) {
				jQuery(this).css('background-position', 'left 0');
			} else {
				jQuery(this).css('background-position', 'left -32px');
			}
			jQuery(this).find('table').css('display', 'none');
		}
	);
}

function InitContactForm() {
	var	wrapper = jQuery('.dropdownWrapper'),
		form = jQuery('.contactsFormWrapper form'),
		submit = form.find('.submitWrapper a');
	
	jQuery.each(wrapper, function() {
		var	ddWrapper = jQuery(this),
			input = ddWrapper.find('input[type="hidden"]'),
			display = ddWrapper.find('.display'),
			button = ddWrapper.find('.button'),
			valuesWrapper = ddWrapper.find('.valueWrapper'),
			values = valuesWrapper.find('li'),
			val = values.filter('[data-value="' + input.val() + '"]');
		
		values.hover(
			function() {
				jQuery(this).css('background-color', '#fafafa');
			},
			function() {
				jQuery(this).css('background-color', 'transparent');
			}
		).click(function() {
			display.html(jQuery(this).html());
			input.val(jQuery(this).attr('data-value'));
			ddWrapper.mouseleave();
		});
		
		button.click(function() {
			var	height = valuesWrapper.find('ul').outerHeight() > 200 ? 200 : valuesWrapper.find('ul').outerHeight();
			valuesWrapper.css({ 'height': height, 'overflow-y': 'auto' });
		});
		ddWrapper.mouseleave(function() {
			valuesWrapper.css({'height': 0, 'overflow': 'hidden' });
		});
		
		if(val.size() > 0) {
			display.html(val.html());
			input.val(val.attr('data-value'));
		} else {
			display.html('');
			input.val('');
		}
	});
	
	submit.click(function(e) {
		e.preventDefault();
		form.submit();
	});
	
	jQuery('.loginlabel').focus(function() {
		jQuery(this).hide();
		jQuery('#login').focus();
	});
	
	jQuery('#login').blur(function() {
		if(jQuery(this).val() == '') {
			jQuery('.loginlabel').show();
		} else {
			jQuery('.loginlabel').hide();
		}
	}).blur();

	jQuery('.passwordlabel').focus(function() {
		jQuery(this).hide();
		jQuery('#password').focus();
	});
	
	jQuery('#password').blur(function() {
		if(jQuery(this).val() == '') {
			jQuery('.passwordlabel').show();
		} else {
			jQuery('.passwordlabel').hide();
		}
	}).blur();
}

function initFlashViewport() {
	jQuery(window).resize(function() {
		var	site = jQuery('.siteContainer'),
			viewport = jQuery('.flashViewport'),
			wrapper = jQuery('.flashWrapper'),
			height = site.height() - 20 - 35,
			width = site.width() - 268,
			top = (viewport.height() - wrapper.height()) / 2,
			left = (viewport.width() - wrapper.width()) / 2;

		viewport.width(width).height(height);
		
		wrapper.css({
			'top': top,
			'left': left
		});
	}).resize();
}

function initInfocenter() {
	var	checkboxes = jQuery('.infocenterWrapper .checkboxItem');
	
	jQuery.each(checkboxes, function() {
		var	checkbox = jQuery(this).find('.checkbox'),
			input = jQuery(this).find('input[type="hidden"]');

		if(input.val() == 'false') {
			input.val('false');
			checkbox.css('background-position', 'left top');
		} else {
			input.val('true');
			checkbox.css('background-position', 'left -13px');
		}

		jQuery(this).click(function() {
			if(input.val() == 'false') {
				input.val('true');
				checkbox.css('background-position', 'left -13px');
			} else {
				input.val('false');
				checkbox.css('background-position' ,'left top');
			}
			loadImages();
		});
	});
	
	checkboxes.first().click();
	
	function loadImages() {
		var	gateway = FOPath + 'public/remoting/infocenter.php',
			parameters = new Object(),
			checkboxes = jQuery('.infocenterWrapper .checkboxItem input[type="hidden"]'),
			values = '',
			first = true;
		
		jQuery.each(checkboxes, function() {
			var	i = jQuery(this),
				str = i.attr('id').split('_');
			if(i.val() == 'true') {
				if(!first) values += ',';
				first = false;
				values += str[1];
			}
		});
		
		parameters.ids = values;
		
		jQuery.ajax({
			data: parameters,
			dataType: "json",
			error: function(jqXHR, textStatus, errorThrown) { alert(textStatus); },
			type: "GET",
			url: gateway,
			success: function (data, textStatus, jqXHR) {
				jQuery('.infocenterViewport .infocenterViewportWrapper').empty();
				render(data, textStatus, jqXHR);
			},
			complete: setupInfocenterPaging
		});
	};
	
	function render(data, textStatus, jqXHR) {
		var	ctr = 1,
			itemStr =		'<div class="infocenterItem">'
						+		'<a target="_blank" href="">'
						+			'<img alt="" src="" width="210" height="126" />'
						+			'<div class="itemText">'
						+				'<div class="title"></div>'
						+				'<div class="desc"></div>'
						+			'</div>'
						+		'</a>'
						+	'</div>';
			separatorStr =	'<div class="infocenterSeparator"></div>';
			clearBothStr =	'<div class="clearBoth"></div>';
			pageStr =		'<div class="infocenterPage"></div>',
			page = null,
			separator = null,
			infocenterItem = null,
			clearBoth = null,
			viewport = jQuery('.infocenterViewport .infocenterViewportWrapper');
			
		//page = jQuery(pageStr);
		//page.appendTo(viewport);
		
		jQuery.each(data, function(index, item) {
			if((ctr - 1) % 6 == 0) {
				page = jQuery(pageStr);
				page.appendTo(viewport);
			}else if((ctr - 1) % 3 == 0) {
				clearBoth = jQuery(clearBothStr);
				clearBoth.appendTo(page);
			}
			
			infocenterItem = jQuery(itemStr);
			infocenterItem.find('a').attr('href', jQuery.base64Decode(item.url));
			infocenterItem.find('img').attr('src', jQuery.base64Decode(item.thumb));
			infocenterItem.find('.title').html(jQuery.base64Decode(item.name));
			infocenterItem.find('.desc').html('&rsaquo;&nbsp;&nbsp;' + jQuery.base64Decode(item.desc));
			
			infocenterItem.appendTo(page);
			
			if(ctr % 3 != 0) {
				separator = jQuery(separatorStr);
				separator.appendTo(page);
			}
			
			ctr++;
		});
	};
	
	function setupInfocenterPaging() {
		var	currentIndex = 0,
			maxIndex = jQuery('.infocenterPage').size() - 1,
			previous = jQuery('.infocenterWrapper .leftWrapper .linksmall a'),
			next = jQuery('.infocenterWrapper .rightWrapper .linksmall a');
		
		jQuery('.infocenterViewport .infocenterViewportWrapper').width((maxIndex + 1) * 650);
		
		next.unbind('click');
		previous.unbind('click');
		
		if(maxIndex <= 0) {
			previous.css('display', 'none');
			next.css('display', 'none');
		} else {
			previous.click(function(e) {
				e.preventDefault();
				var	slider = jQuery('.infocenterViewport .infocenterViewportWrapper');
				currentIndex--;
				if(currentIndex < 0) currentIndex = 0;
				
				if(currentIndex == 0) {
					previous.css('display', 'none');
				} else {
					previous.css('display', 'block');
				}
				
				if(currentIndex < maxIndex) {
					next.css('display', 'block');
				} else {
					next.css('display', 'none');
				}
				
				slider.stop().animate({
					left: - (currentIndex * 650)
				}, 1000);
			});
			next.click(function(e) {
				e.preventDefault();
				var	slider = jQuery('.infocenterViewport .infocenterViewportWrapper');
				currentIndex++;
				if(currentIndex > maxIndex) currentIndex = maxIndex;
				
				if(currentIndex == maxIndex) {
					next.css('display', 'none');
				} else {
					next.css('display', 'block');
				}
				
				if(currentIndex > 0) {
					previous.css('display', 'block');
				} else {
					previous.css('display', 'none');
				}
				
				slider.stop().animate({
					left: - (currentIndex * 650)
				}, 1000);
			});
			previous.css('display', 'none');
			next.css('display', 'block');
		}
	};
}

function SetupValuesOverlays() {
	var	site = jQuery('.siteContainer'),
		footer = jQuery('.footerWrapper')
		valueLeftSingle = jQuery('.valueLeftSingle'),
		valueRightSingle = jQuery('.valueRightSingle'),
		valueLeftTop = jQuery('.valueLeftTop'),
		valueLeftBottom = jQuery('.valueLeftBottom'),
		height = 0;
	
	if(valueLeftSingle.size() > 0) {
		var	overlayls = valueLeftSingle.find('.overlay'),
			imgls = valueLeftSingle.find('.background').css('cursor', 'pointer'),
			cst = 1,
			offsetleftls = 0,
			offsettopls = 0;
		
		imgls.data('height', imgls.height());
		imgls.data('width', imgls.width());
		
		jQuery(window).resize(function() {
			height = site.height() - footer.height();
			valueLeftSingle.height(height);
			overlayls.height(height).width(138);
			
			if(imgls.data('height') < height) {
				cst = height / imgls.data('height');
			}
			
			offsetleftls = imgls.attr('data-offsetleft') * cst - (overlayls.width() / 2);
			
			if(offsetleftls < 0) offsetleftls = 0;
			
			offsettopls = imgls.attr('data-offsettop') * cst - (overlayls.height() / 2);
			if(offsettopls < 0) offsettopls = 0;
			
			imgls.css({
				left: - offsetleftls,
				height: cst * imgls.data('height'),
				top: - offsettopls,
				width: cst * imgls.data('width')
			});
		}).resize();

		imgls.hover(
			function() {
				jQuery(this).stop().animate({
					left: - offsetleftls - 10,
					height: cst * imgls.data('height') + 20,
					top: -offsettopls - 10,
					width: cst * imgls.data('width') + 20
				}, 100);
			},
			function() {
				jQuery(this).stop().animate({
					left: - offsetleftls,
					height: cst * imgls.data('height'),
					top: -offsettopls,
					width: cst * imgls.data('width')
				}, 100);}
		);
	}
	
	if(valueRightSingle.size() > 0) {
		var	overlayrs = valueRightSingle.find('.overlay'),
			imgrs = valueRightSingle.find('.background').css('cursor', 'pointer'),
			cstrs = 1,
			offsetleftrs = 0,
			offsettoprs = 0,
			isClickBound = false;
		
		imgrs.data('height', imgrs.height());
		imgrs.data('width', imgrs.width());
		
		jQuery(window).resize(function() {
			offsetleftrs = imgrs.attr('data-offsetleft') * cstrs - (overlayrs.width() * 0,3);
			
			if(offsetleftrs < 0) offsetleftrs = 0;
			
			offsettoprs = imgrs.attr('data-offsettop') * cstrs - (overlayrs.height() * 0,3);
			if(offsettoprs < 0) offsettoprs = 0;
			
			imgrs.css({
				left: - offsetleftrs,
				height: cstrs * imgrs.data('height'),
				top: - offsettoprs,
				width: cstrs * imgrs.data('width')
			});
		}).resize();

		imgrs.hover(
			function() {
				jQuery(this).stop().animate({
					left: - offsetleftrs - 10,
					height: cstrs * imgrs.data('height') + 20,
					top: -offsettoprs - 10,
					width: cstrs * imgrs.data('width') + 20
				}, 100);
			},
			function() {
				jQuery(this).stop().animate({
					left: - offsetleftrs,
					height: cstrs * imgrs.data('height'),
					top: -offsettoprs,
					width: cstrs * imgrs.data('width')
				}, 100);}
		);
		
		valueRightSingle.mousemove(function(e) {
			var	x = e.clientX - jQuery(this).offset().left,
				y = e.clientY - jQuery(this).offset().top;
			
			if(x > 320 - y && y > 309 - x) {
				valueRightSingle.css('cursor', 'pointer');
				if(!isClickBound) {
					imgrs.mouseenter();
					isClickBound = true;
					jQuery(this).click(function() {
						window.location = jQuery(this).find('a').attr('href');
					});
				}
			} else {
				
				if(isClickBound) {
					imgrs.mouseleave();
					isClickBound = false;
					jQuery(this).unbind('click');
				}
				valueRightSingle.css('cursor', 'default');
			}
		});
	}
	
	if(valueLeftTop.size() > 0) {
		var	overlaylt = valueLeftTop.find('.overlay'),
			imglt = valueLeftTop.find('.background').css('cursor', 'pointer'),
			cstlt = 1,
			offsetleftlt = 0,
			offsettoplt = 0;

		imglt.data('height', imglt.height());
		imglt.data('width', imglt.width());
		
		jQuery(window).resize(function() {
			overlaylt.height(valueLeftTop.height());

			offsetleftlt = imglt.attr('data-offsetleft') * cstlt - (overlaylt.width() * 0,3);
			
			if(offsetleftlt < 0) offsetleftlt = 0;
			
			offsettoplt = imglt.attr('data-offsettop') * cstlt - (overlaylt.height() * 0,3);
			if(offsettoplt < 0) offsettoplt = 0;
			
			imglt.css({
				left: - offsetleftlt,
				height: cstlt * imglt.data('height'),
				top: - offsettoplt,
				width: cstlt * imglt.data('width')
			});
		}).resize();

		imglt.hover(
			function() {
				jQuery(this).stop().animate({
					left: - offsetleftlt - 10,
					height: cstlt * imglt.data('height') + 20,
					top: -offsettoplt - 10,
					width: cstlt * imglt.data('width') + 20
				}, 100);
			},
			function() {
				jQuery(this).stop().animate({
					left: - offsetleftlt,
					height: cstlt * imglt.data('height'),
					top: -offsettoplt,
					width: cstlt * imglt.data('width')
				}, 100);
			}
		);
	}
	
	if(valueLeftBottom.size() > 0) {
		var	overlaylb = valueLeftBottom.find('.overlay'),
		imglb = valueLeftBottom.find('.background').css('cursor', 'pointer'),
		cstlb = 1,
		offsetleftlb = 0,
		offsettoplb = 0;
		
		jQuery(window).resize(function() {
			overlaylb.height(valueLeftBottom.height());

			offsetleftlb = imglb.attr('data-offsetleft') * cstlb - (overlaylb.width() * 0,3);
			
			if(offsetleftlb < 0) offsetleftlb = 0;
			
			offsettoplb = imglb.attr('data-offsettop') * cstlb - (overlaylb.height() * 0,3);
			if(offsettoplb < 0) offsettoplb = 0;
			
			imglb.css({
				left: - offsetleftlb,
				height: cstlb * imglb.data('height'),
				top: - offsettoplb,
				width: cstlb * imglb.data('width')
			});
		}).resize();

		imglb.hover(
			function() {
				jQuery(this).stop().animate({
					left: - offsetleftlb - 10,
					height: cstlb * imglb.data('height') + 20,
					top: -offsettoplb - 10,
					width: cstlb * imglb.data('width') + 20
				}, 100);
			},
			function() {
				jQuery(this).stop().animate({
					left: - offsetleftlb,
					height: cstlb * imglb.data('height'),
					top: -offsettoplb,
					width: cstlb * imglb.data('width')
				}, 100);
			}
		);
	}
	
}
