// JavaScript Document

// home page
function setCatBackground(catDesc,imgLink){
		jQuery('img',"#categories_homepage").each(function(){
			jQuery(this).attr("src",imgLink + "home_link_begin.png");
		});
		jQuery('a',"#categories_homepage").each(function(){			
			jQuery(this).attr("class","home_link_end");
		});
		var beginImg = jQuery("#begining_"+catDesc);
		beginImg.attr("src",imgLink + "home_link_begin_hover.png");
		var catUrl	= jQuery("#url_"+catDesc);
		catUrl.attr("class","home_link_end_hover");		
		jQuery("#categories_homepage").attr('class','categories_home_' + catDesc)
	}

function initTabs() {
	var use_anchor = true;
	var tabContainers = jQuery('div.tabs > div');
	jQuery('div.tabs ul.tabNavigation a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			jQuery('div.tabs ul.tabNavigation a').removeClass('selected');
			jQuery(this).addClass('selected');
			return false;
		}).filter(':first').click();
	// Get the URL
	var uri = document.location.toString();
	// if the URL contains an anchor show div where id equals anchor
	if (uri.match('#') && use_anchor) {
	  var uriAnchor = '#' + uri.split('#')[1];
	  jQuery('div.tabs ul.tabNavigation a[href="' + uriAnchor + '"]').click();
	  use_anchor = false;
	} else {
		tabContainers.hide().filter(':first').show();
	}
}

jQuery(document).ready(function(){
    initTabs();
    
    /* fancybox */
	jQuery("a.fancybox-image").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600,
		'speedOut'		:	200,
    	'titleShow'     : false

	});

    jQuery("a.youtube").fancybox({
            'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'width'         : 680,
			'height'		: 495,
			'href'			: this.href,//.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
    });

    jQuery('.leasinginfo').tooltip({
        delay: 0,
        showURL: false,
		position:'bottom center',
        bodyHandler: function() {
            return document.getElementById('leasinginfoblock').innerHTML;

        }
    });

    jQuery('#gymna-submission-form-show').click(function() {
        jQuery('.form-block').toggle();
    });
	
	jQuery('.project-tooltip').tooltip({tipClass:'project-tooltip-txt',position:'bottom right'});
	jQuery('.icon-tooltip').tooltip({tipClass:'project-tooltip-txt',position:'bottom right'});

        jQuery('.agenda-tooltip').tooltip({tipClass:'agenda-tooltip-txt',position:'bottom right'});

	jQuery(".increase").bind("click", function() {resizeText(5);});
	jQuery(".normal").bind("click", function() {resizeText(0);});
	jQuery(".decrease").bind("click", function() {resizeText(3);});
	
	jQuery('.gymna-account').bind("mouseenter", function() { jQuery('.news > .container').show(); });
	jQuery('.gymna-account').bind("mouseleave", function() { jQuery('.news > .container').hide(); });

    /* login window */
    if (jQuery(".node-popup").length > 0) {
        jQuery.fancybox(
            jQuery(".node-popup").html(),
            {
                'autoDimensions'    : true,
                'transitionIn'      : 'none',
                'transitionOut'     : 'none'
            }
	);
    }
    
    jQuery('a.popup-close').click(function() {
        jQuery.fancybox.close();
    })


});

function initLoginWindow() {
    jQuery('#showRegisteredUsers').click(function() {
        jQuery('#registeredusers').removeClass('NoScreenDisplay');
        jQuery('#header_two').removeClass('NoScreenDisplay');
        jQuery('#login_one').addClass('NoScreenDisplay');
        jQuery('#header_one').addClass('NoScreenDisplay');
    });
}

function resizeText(multiplier) {
  if (document.body.style.fontSize == "") {
    document.body.style.fontSize = "0.75em";
  }
  
  if(multiplier == 0){
	  document.body.style.fontSize = "0.75em";
  }else{
  	document.body.style.fontSize = (multiplier * 0.2) + "em";
  }
}
