// main doc ready function for all pages

$(document).ready(function(){
	docInitFunction();
});

function docInitFunction(){
	var arrayPageSize = getpagesize();
	$('#whiteoutdiv').width(arrayPageSize[0]);
	$('#whiteoutdiv').height(arrayPageSize[1]);

	$('#fav-menu-item').bind('mouseenter', function() {
		$('#watch-dropdown').hide();
		$('#fav-dropdown').slideDown('slow');
	});

	$('#fav-dropdown').bind('mouseleave', function() {
		$('#fav-dropdown').slideUp('slow');
	});

	$('#watch-menu-item').bind('mouseenter', function() {
		$('#fav-dropdown').hide();
		$('#watch-dropdown').slideDown('slow');
	});

	$('#watch-dropdown').bind('mouseleave', function() {
		$('#watch-dropdown').slideUp('slow');
	});

	$('#header-links>ul>li>a').click(function() {

		switch($(this).html())
		{
		case "login":
		  var ajaxurl = "/login.php";
		  break;
		case "join":
		  var ajaxurl = "/join.php";
		  break;
		default:
		   var ajaxurl = "";
		}
		
		if(ajaxurl!=""){

			$('#largememberdivcontent').attr('src',ajaxurl);

			if($.browser.msie)
				$('#whiteoutdiv').show();
			else
				$('#whiteoutdiv').fadeIn('slow');
			$('#largememberdiv').fadeIn('slow');
			$('#largememberdivclose').show();
		}
	});


	$('.loginlink').click(function() {
			$('#largememberdivcontent').attr('src','/login.php');

			if($.browser.msie)
				$('#whiteoutdiv').show();
			else
				$('#whiteoutdiv').fadeIn('slow');
			$('#largememberdiv').fadeIn('slow');
			$('#largememberdivclose').show();
	});

	$('.joinlink').click(function() {
			$('#largememberdivcontent').attr('src','/join.php');

			if($.browser.msie)
				$('#whiteoutdiv').show();
			else
				$('#whiteoutdiv').fadeIn('slow');
			$('#largememberdiv').fadeIn('slow');
			$('#largememberdivclose').show();
	});


	$('#largememberdivclose>a').click(function() {
		$('#largememberdiv').fadeOut('slow');
		$('#largememberdivclose').fadeOut('slow');
		if($.browser.msie)
			$('#whiteoutdiv').hide();
		else
			$('#whiteoutdiv').fadeOut('slow');
	});

	var menu_t;

	$('.mainnavlink').bind('mouseenter', function() {

			menu_t = setTimeout(function() {
			$('#largemenudivcontent>ul>li').hide();
			var sm = $('a',this).html();
			$('div.largemenudivinfo>h4').html($('#largemenudivcontent>ul>li[class="'+sm+'"]>ul.largemenudivmenu>li>a').html());
			$('div.largemenudivinfo>p').html($('#largemenudivcontent>ul>li[class="'+sm+'"]>ul.largemenudivmenu>li>a').attr('rel'));
			$('#largemenudivcontent>ul>li[class="'+sm+'"]').show();
	
			if($.browser.msie)
				$('#whiteoutdiv').show();
			else
				$('#whiteoutdiv').fadeIn('slow');
			$('#largemenudiv').slideDown('slow');
  		}, 500);
	});

	$('.mainnavlink').bind('mouseleave', function() {

			clearTimeout(menu_t);
	});
		
	$('.mainnavpopuplink').bind('mouseenter', function() {
		$('.mainnavpopuplink').css('background-color','#ffffff');
		$('.mainnavpopuplink>a').css('color','#99001D');
		$(this).css('background-color','#ff0000');
		$('a',this).css('color','#ffffff');
		$('#largemenudivcontent>ul>li').hide();
		var sm = $('a',this).html();
		$('div.largemenudivinfo>h4').html($('#largemenudivcontent>ul>li[class="'+sm+'"]>ul.largemenudivmenu>li>a').html());
		$('div.largemenudivinfo>p').html($('#largemenudivcontent>ul>li[class="'+sm+'"]>ul.largemenudivmenu>li>a').attr('rel'));
		$('#largemenudivcontent>ul>li[class="'+sm+'"]').show();

	});

	$('#largemenudiv').bind("mouseleave", function() {
  		$('#largemenudiv').slideUp('slow');
		if($.browser.msie)
			$('#whiteoutdiv').hide();
		else
			$('#whiteoutdiv').fadeOut('slow');
	});

	$('ul.largemenudivmenu>li>a').bind('mouseenter', function() {
		$('div.largemenudivinfo>h4').html($(this).html());
		$('div.largemenudivinfo>p').html($(this).attr('rel'));

	});

	$('.but-plus').click(function() {

		var s = $("body").css('font-size').replace('px','');
		if(isNaN(parseFloat(s)))s = '12.8';
		var z = parseFloat(s)
		z = 1.05*z;
		s = z+'px';
		if(z<17)$('body').css('font-size',s);
	});

	$('.but-minus').click(function() {

		var s = $("body").css('font-size').replace('px','');
		if(isNaN(parseFloat(s)))s = '12.8';
		var z = parseFloat(s)
		z = 0.85*z;
		s = z+'px';
		if(z>10)$('body').css('font-size',s);
	});

	$('.but-t').click(function() {
		$('body').css('font-size','12.8px');
	});

	$('.btn_profile').click(function() {
	
			window.location.href='/profile-edit';

	});



	$('.profile_features1').bind("mouseenter", function() {
		$('#profile_features1_popup').show();

	});

	$('.profile_features2').bind("mouseenter", function() {
		$('#profile_features2_popup').show();

	});

	$('.profile_features3').bind("mouseenter", function() {
		$('#profile_features3_popup').show();

	});

	$('.profile_features1').bind("mouseleave", function() {
		$('#profile_features1_popup').hide();

	});

	$('.profile_features2').bind("mouseleave", function() {
		$('#profile_features2_popup').hide();

	});

	$('.profile_features3').bind("mouseleave", function() {
		$('#profile_features3_popup').hide();

	});


	$('.btn_profile_cancel').click(function() {
		
		window.location.href='/profile';

	});

	$('.btn_profile_save').click(function() {
		
		$("#memberform").submit();

	});

		//create bubble popups for each element with class "button"
		$('.bubble').CreateBubblePopup();
	
		//set customized mouseover event for each button
		$('.bubble').mouseover(function(){
	
			//show the bubble popup with new options
			$(this).ShowBubblePopup({
										innerHtml: $(this).attr('rel'),
										width: '300px',					
										themeName: 	'all-orange',
										innerHtmlStyle: {
																				color:'	#ffffff', 
																				'text-align':'left'
																			},			
										themePath: 	'/css'								 
								  });
		});


} // end docInitFunction





//	Function taken from Lightbox v2.04
//	by Lokesh Dhakar - http://www.lokeshdhakar.com
//	Last Modification: 2/9/08
//
//	For more information, visit:
//	http://lokeshdhakar.com/projects/lightbox2/


function getpagesize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}



