function mainmenu(){
$(" #nav ul ").css({display: "none"});
$(" #nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

function InfoRollovers() {
	$('#regNav img').hover(function(){
		$(this).attr('src' , $(this).attr("src").split("_off.").join("_on."))},
	function(){
		$(this).attr('src' , $(this).attr("src").split("_on.").join("_off."))
	})
}

$(document).ready(function(){
$("#login img").hover(
function()
{
		$(this).attr('src' , $(this).attr("src").split("_off.").join("_on."))
},
function()
{
		$(this).attr('src' , $(this).attr("src").split("_on.").join("_off."))
});
});

function showfT() 
{
	hideAll()
	$('#fT').fadeIn("slow");
}

function showgS()
{
	hideAll()
	$('#gS').fadeIn("slow");
}

function showtT() 
{
	hideAll()
	$('#tT').fadeIn("slow");
}

function showtG() 
{
	hideAll()
	$('#tG').fadeIn("slow");
}

function showbL() 
{
	hideAll()	
	$('#bL').fadeIn("slow");
}

function showsP() 
{
	hideAll()	
	$('#sP').fadeIn("slow");
}

function showeP() 
{
	hideAll()
	$('#eP').fadeIn("slow");
}

function hideAll() 
{
	$('#fT').hide();
	$('#gS').hide();
	$('#tT').hide();
	$('#tG').hide();
	$('#sP').hide();
	$('#bL').hide();
	$('#eP').hide();
}

//this is the jquery for the partners page
function partners(){
$("ul.thumb li").hover(function() {
	$(this).css({'z-index' : '10'});
	$(this).find('img').addClass("hover").stop()
		.animate({
			marginTop: '-110px', 
			marginLeft: '-110px', 
			top: '50%', 
			left: '50%', 
			width: '174px', 
			height: '174px',
			padding: '0px' 
		}, 200);
	
	} , function() {
	$(this).css({'z-index' : '0'});
	$(this).find('img').removeClass("hover").stop()
		.animate({
			marginTop: '0', 
			marginLeft: '0',
			top: '0', 
			left: '0', 
			width: '100px', 
			height: '100px', 
			padding: '5px'
		}, 400);
});
};

$(document).ready(function(){
	var queryString = document.URL.split('?query='); 
	switch (queryString[1])
	{
		case "1":
		showDLogin()
		break; 
		case "2":
		showMLogin()
		break; 
		case "3":
		showBLogin()
		break; 
		case "4":
		showTLogin()
		break;
		default:
		showDLogin()
	}
});

function showDLogin()
{
	hideAllLogins()
	$('#dLogin').fadeIn("slow");
	$('#lIn').fadeIn('slow');
}

function showMLogin() 
{
	hideAllLogins()
	$('#mLogin').fadeIn("slow");
	$('#pIn').fadeIn('slow');
}

function showBLogin() 
{
	hideAllLogins()
	$('#bLogin').fadeIn("slow");
	$('#lIn').fadeIn('slow');
}

function showTLogin() 
{
	hideAllLogins()
	$('#tLogin').fadeIn("slow");
	$('#lIn').fadeIn('slow');
}

function hideAllLogins()
{
	$('#dLogin').hide();
	$('#mLogin').hide();
	$('#bLogin').hide();
	$('#tLogin').hide();
	$('#lIn').hide();
	$('#pIn').hide();
	
}



/////temporary Video BS//////////
function hideVideos()
{
	$('#d1').hide();
	$('#d2').hide();
	$('#d3').hide();
	$('#bw').hide();
	$('#mh1').hide();
	$('#mh2').hide();
}

hideVideos()


function showdVid1()
{
	hideVideos()
	$('#d1').show();
}

function showdVid2()
{
	hideVideos()
	$('#d2').show();
}
function showdVid3()
{
	hideVideos()
	$('#d3').show();
}
function showbwVid()
{
	hideVideos()
	$('#bw').show();
}
function showmhVid1()
{
	hideVideos()
	$('#mh1').show();
}
function showmhVid2()
{
	hideVideos()
	$('#mh2').show();
}
//////end the BS/////////////

// Google Check Cookie ///

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { 
        options = options || {};
        if (value == null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }
  
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
           
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function createCookie()
{
	var url = document.URL.split('?search=')[1];
	$.cookie("urlOrigin",url, {path:'/'});
	if (document.getElementById('CampCode'))
	{
		document.getElementById('CampCode').value = $.cookie('urlOrigin');
	}
}


var i = 4; 

//This is the slideshow rotator function
$(document).ready(function(){
	var pic = $(".slideShow");
	var i = 0; 
	$(pic[i]).css({opacity:'1'}); 
	setInterval(switchImage, 8000); 
	
	function switchImage()
	{
		i++; 
		$(pic[i]).animate({opacity:'1'}, 600); 
		if (i >= 5)
		{
			i = 0; 
			$(pic[1]).animate({opacity:'0'}, 90); 
			$(pic[2]).animate({opacity:'0'}, 90); 
			$(pic[3]).animate({opacity:'0'}, 90); 
			$(pic[4]).animate({opacity:'0'}, 90); 
		}
	}
});


function toggleTerms(str)
{
	switch (str)
	{
		case "doc":
		$('#docButton1').css('background-image','url("images/mainContent/Headings/Doctors-Providers_on.png")'); 
		$('#patButton1').css('background-image','url("images/mainContent/Headings/Patients.png")'); 
		$('#doctorTerms').css({display: "block"});
		$('#patientTerms').css({display: "none"});
		break; 
		case "pat":
		$('#docButton1').css('background-image','url("images/mainContent/Headings/Doctors-Providers.png")'); 
		$('#patButton1').css('background-image','url("images/mainContent/Headings/Patients_on.png")'); 
		$('#doctorTerms').css({display: "none"}); 
		$('#patientTerms').css({display: "block"});
			break; 
	}
}

function OpenNewWindow(url)
{
	var h = window.screen.height;
	var w = window.screen.width;
	var options = "status=yes,toolbar=no,directories=no,personalbar=no,resizable=no, scrollbars=yes, left=0, top=0, width=" + w +",height=" + h;
	window.open(url,"Doctations", options);
}



function toggleDidYouKnow(thumb) {
	full = document.getElementById(thumb.id + "_full");
	hideAllDivs(); 
	$(full).fadeIn(500);
}

function hideAllDivs() {
	$('#didYouKnowContainer').find("div").hide(); 
}

function showFirstDiv() {
	$("#didYouKnowContainer div:first-child").fadeIn(3000); 
}

//////////////////////////////////////////////////scrolling nav/////////
function makeScrollable(wrapper, scrollable){
	// Get jQuery elements
	var wrapper = $(wrapper), scrollable = $(scrollable);
	
	// Hide images until they are not loaded
	scrollable.hide();
	var loading = $('<div class="loading">Loading...</div>').appendTo(wrapper);
	
	// Set function that will check if all images are loaded
	var interval = setInterval(function(){
		var images = scrollable.find('img');
		var completed = 0;
		images.animate({opacity: "0.4"},500);
		images.hover(
			function()
			{
				$(this).stop().animate({opacity: "1.0"},500);
			},
			function()
			{
				$(this).stop().animate({opacity: "0.4"},500);
			});
		
		// Counts number of images that are succesfully loaded
		images.each(function(){
			if (this.complete) completed++;	
		});
		
		if (completed == images.length){
			clearInterval(interval);
			// Timeout added to fix problem with Chrome
			setTimeout(function(){
				
				loading.hide();
				// Remove scrollbars	
				wrapper.css({overflow: 'hidden'});						
				
				scrollable.slideDown('slow', function(){
					enable();	
				});					
			}, 1000);	
		}
	}, 100);
	
	function enable(){			
		// height of area at the top at bottom, that don't respond to mousemove
		var inactiveMargin = 100;
		// Cache for performance
		var wrapperWidth = wrapper.width();
		var wrapperHeight = wrapper.height();
		// Using outer height to include padding too
		var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
		// Do not cache wrapperOffset, because it can change when user resizes window
		// We could use onresize event, but it's just not worth doing that 
		// var wrapperOffset = wrapper.offset();
		
		//When user move mouse over menu			
		wrapper.mousemove(function(e){
			var wrapperOffset = wrapper.offset();
			// Scroll menu
			var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;	
			
			if (top < 0){
				top = 0;
			}
			
			wrapper.scrollTop(top);
		});		
	}
}


function welcome_name()
{
	var welcome_name = document.getElementById('welcome_name'); 
	if ($.cookie('RealName'))
	{
		welcome_name.innerHTML = "<p>welcome, <span class='red_text'>"+ $.cookie('RealName') + "</span></p>"; 
	}
}

function changeYear()
{
	var currentYear = (new Date).getFullYear();
	$('#sub-footer').find('ul li:first').html('&copy;2008-'+currentYear+' DocPatient Network, Inc. |');
}


$(document).ready
(
 	mainmenu(),
	showfT(), 
	InfoRollovers(),
	partners(), 
	createCookie(),
	showFirstDiv(),
	makeScrollable("div.sc_menu_wrapper", "div.sc_menu"), 
	welcome_name(), 
	changeYear()
);

