$(document).ready(function(){
	img_popupImage(true,null);
	menu_initScroll();
});
function img_popupImage(blnInit,objImg){
	if(blnInit){
		$('#cont-middle span[media="image"]').each(function(){
			if($(this).children().length>0){
				$(this)
					.css('cursor','pointer')
					.attr('title','Click to see a larger image')
					.bind('click',function(){
						img_popupImage(false,$(this).children('img'));
					});
			}
		});
	}else{
		$('<div id="popup-overlay" class="popup-overlay"></div>')
			.css({"opacity": "0.8"})
			.width($(document).width())
			.height($(document).height())
			.prependTo('body')
			.fadeIn(300,function(){
				$(this).bind('click',function(){popup_close();});
				$('<div id="popup" class="popup-window wc-roundBorder wc-boxShadow"></div>')
					.prependTo('body');
				$('<img src="' + objImg.attr('src') + '" />')
					.css('cursor','pointer')
					.appendTo($('#popup'))
					.bind('click',function(){popup_close();});
				$('<div class="popup-toolbar"></div>')
					.css('width',$('#popup').width())
					.appendTo($('#popup'));
				$('<div class="popup-close" title="Close window"></div>')
					.bind('click',function(){popup_close();})
					.appendTo('.popup-toolbar');
				popup_position($('#popup'));
			});	
			$(window)
			.resize(function(){popup_position($('#popup'));});
	}
}
function popup_close(){
	$('#popup').remove();
	$('#popup-overlay').fadeOut(300);
	$(window).resize(null);
}
function popup_position(objPopup){
	var docWidth = $(window).width();
	var docHeight = $(window).height();
	objPopup.css('left',((docWidth/2)-objPopup.width()/2));
	objPopup.css('top',((docHeight/2)-objPopup.height()/2));
}
function feedback_createInfoBox(objTarget,boxId,boxWidth,boxStyle,boxMessage){
	if($('#' + boxId).length>0){
		$('#' + boxId)
			.removeAttr('class')
			.addClass('info-box ' + boxStyle)
			.html(boxMessage);
	}else{
		$('<div></div>')
			.attr('id',boxId)
			.css('width',boxWidth + 'px')
			.addClass('info-box ' + boxStyle)
			.html(boxMessage)
			.prependTo(objTarget)
			.show();
	}
}
function menu_initScroll(){
	var windowHeight = $(window).height();
	var menuHeight = $('.col-left').height();
	var bodyHeight = $('.wc-middle').height();
	var menuOffset = ($('.col-left').offset().top+150);
	if(menuHeight<bodyHeight && windowHeight>menuHeight){
		$(window).scroll(function() {
				if($(this).scrollTop()>menuOffset){
					if((($(this).scrollTop()-menuOffset)+menuHeight)<bodyHeight){
						$('.col-left').stop().animate({'top' : ($(this).scrollTop()-menuOffset) +'px'}, 350);
					}
				}else{
					$('.col-left').stop().animate({'top' : '0px'},350);
				}
		});
	}
}

