/*********************************************************/
// @todo add fixed positioning support, widget-positioning-fixed

var isReport = true;

YUI().use('node', 'node-event-simulate', 'cookie', function(Y){
	changeSize = function(size){
		/* set a base value the percentages will work off of */
		var px_size = '13px';
		if (size == 'small') {
			px_size = '13px';
		}
		else if (size == 'medium') {
			px_size = '14px';
		}
		else if (size == 'large') {
			px_size = '15px';
		}

		Y.Node.all('.main_content, .right_column, .pot_lightbox .yui-widget-bd, .left_column, .carousel_page_content').each(function(el) {
			el.setStyle('fontSize', px_size);
		});

		var path = '/' + window.location.pathname.split('/').splice(1, 2).join('/') + '/';
		Y.Cookie.set("PCS_REPORT_FONT_SIZE", px_size, {path : path});
	}
	
	changeSizeToggle = function () {
		changeSize(size);
		if(size == 'large')
		{
			size = 'small';
		}
		else
		{
			size = 'large';
		}			
	}

	Y.on('domready', function() {
		var size = Y.Cookie.get("PCS_REPORT_FONT_SIZE");
		Y.Node.all('.main_content, .right_column, .pot_lightbox .yui-widget-bd, .carousel_page_content').each(function(el) {
			el.setStyle('fontSize', size);
		});
	});

	function fireFlashLightbox(href, classes){
		var node = Y.Node.create('<a href="' + href + '" class="zu_lightbox ' + classes.join(' ') + '"></a>');
		Y.one('body').append(node);
		node.simulate('click');
		node.remove();
	}
	function submitKeywords(form_id, caller, link){
		var form = Y.one('#'+form_id),
			action = form.getAttribute('action'),
			href = link.get('href').split('/');
		href = href[(href.length-1)];
		if (caller == 'lightbox') {
			window.location.href = action + href + '/';
		}
		else {
			var popup_settings = 'status=1,toolbar=0,location=1,menubar=0,directories=1,resizable=yes,';
			if (href == '') {
				var act = action.split('keywords');
				href = act[0] + 'what_keywords/';
				popup_settings += 'scrollbars=no,width=550,height=525';
			}
			else {
				href = action + href + '/';
				popup_settings += 'scrollbars=yes,width=400,height=525';
			}
			window.open(href, '_blank', popup_settings);
		}

		return false;
	}
	// in main nav
	Y.on('click', function(e){
		e.preventDefault();
		submitKeywords('keywords', '', e.currentTarget);
	}, '.navigation_bar ul.NFSelectOptions li a', this);
	// on keywords page
	Y.on('click', function(e){
		e.preventDefault();
		submitKeywords('keywords', 'lightbox', e.currentTarget);
	}, '.lightbox_template ul.NFSelectOptions li a', this);
	var opts = Y.all('#keywords select option');
	opts.each(function(v) {
		if (v.get('value') != '') {
			v.set('innerHTML', '&nbsp;&nbsp;'+v.get('innerHTML'));
		}
	});
});

