$(document).ready(function() { //document.ready jquery call go in here
	// Detect IE6
	var ie6 = false;
	if(jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) {
			ie6 = true;
		}
	}
	if(!ie6) {  // Start if not IE6
		
		
	// slider positions
		var sliderOne = '540px';
		var sliderTwo = '390px';
		var sliderThree = '222px';
		var sliderFour = '55px';
		
		var sliderSpeed = '800';
		

	//initiate cycle 
	$(window).load(function () {
			//add slider controls to page
			$('#slide-controls').append('<li id="ctrl-back"><a href="#"></a></li><li id="ctrl-play" style="display:none;"><a href="#"></a></li><li id="ctrl-pause"><a href="#"></a></li><li id="ctrl-next"><a href="#"></a></li>');
			$('#slide-controls').before('<span id="ctrl-slider"></span>');
			// cyle plugin fuctions
//			$('#slide-holder').cycle({ 
//		  		fx: 'fade',
//				speed: 700,
//				timeout: 8000,
//				autostop: 1,
//				autostopCount: 5,
//				containerResize: 0,
//				end: showPlayBtn,
//				before: sliderCall,
//				prev: '#ctrl-back',
//				next: '#ctrl-next'
//			});
//				
			
			//slider position callback function
			function sliderCall(curr, next, opts) {
				var slideid = next.id ;				
				//console.log(slideid)				
				if (slideid == 'accounting-careers') {
					$('#ctrl-slider').stop().animate({"right": sliderOne}, sliderSpeed);
		        }				
				if (slideid == 'about-us') {
					$('#ctrl-slider').stop().animate({"right": sliderTwo}, sliderSpeed);
		        }
				if (slideid == 'flexible-study') {
					$('#ctrl-slider').stop().animate({"right": sliderThree}, sliderSpeed);
		        }
				if (slideid == 'financial-aid') {
					$('#ctrl-slider').stop().animate({"right": sliderFour}, sliderSpeed);
		        }
				else {
		            return;
		       }
			};
		

			function showPauseBtn() {
				$('#ctrl-play').hide();	$('#ctrl-pause').show();
			};
			function showPlayBtn() {
				$('#ctrl-pause').hide(); $('#ctrl-play').show();
			};
			
			
			//add play/pause controls
			$('#ctrl-pause').click(function() { 
			    $('#slide-holder').cycle('pause');
				$(this).hide();
				$('#ctrl-play').show();
				return false; 
			});
			$('#ctrl-play').click(function() {
				$('#slide-holder').cycle('resume',true);
				$('#ctrl-pause').show();
				$(this).hide();
				return false; 
			});
		
		
		
	
			// Pause Show fuction
			function pauseShow() {
			    $('#slide-holder').cycle('pause');
				$('#ctrl-play').show();
				$('#ctrl-pause').hide();
			};
		
			$('#ctrl-accounting-careers').click(function() {
				$('#slide-holder').cycle(0);
				$('#ctrl-slider').stop().animate({"right": sliderOne}, sliderSpeed);
				pauseShow();
			    return false; 
			});
			$('#ctrl-about-us').click(function() { 
				$('#slide-holder').cycle(1);
				$('#ctrl-slider').stop().animate({"right": sliderTwo}, sliderSpeed);
				pauseShow();
			    return false; 
			});
			$('#ctrl-flexible-study').click(function() { 
				$('#slide-holder').cycle(2);
				$('#ctrl-slider').stop().animate({"right": sliderThree}, sliderSpeed);
				pauseShow();
			    return false;
			});
			$('#ctrl-financial-aid').click(function() { 
				$('#slide-holder').cycle(3);
				$('#ctrl-slider').stop().animate({"right": sliderFour}, sliderSpeed);
				pauseShow();
			    return false; 
			});
		
		
		
		
				// menu call
				$(function menuCall() {
				    var time = 500;
				    var hideDelay = 250;
				    var hideDelayTimer = null;
				    var beingShown = false;
				    var shown = false;
					var initialHover = false;
					var initial = false;
				    var trigger = $('#nav-call', this);
				    var info = $('#nav', this).css({ opacity: "0"});

				    $([trigger.get(0), info.get(0)]).mouseover(function () {
				        if (hideDelayTimer) clearTimeout(hideDelayTimer);
						if (beingShown || shown) {
				            // don't trigger the animation again
				            return;
				        } else {
				            // reset position of info box
				            beingShown = true;
							initialHover = true;
				           	info.css({
				                top: 19,
				                display: 'block'
				            }).animate({
				               	height: 140,
				                opacity: 1
				            }, time, 'swing', function() {
				                beingShown = false;
				                shown = true;
				            });
				        }
				        return false;
				    }).mouseout(function () {
				        if (hideDelayTimer) clearTimeout(hideDelayTimer);
				        hideDelayTimer = setTimeout(function () {
				            hideDelayTimer = null;
							info.animate({
								opacity: .5,
								height: 0
							}, time, 'swing', function () {
							    shown = false;
							    info.css('display', 'none');
							});

				        }, hideDelay);
				        return false;
				    });
					function hideMenu() {
						if (initialHover || initial) {
				            // don't trigger the animation again
				            return;
				        } else {
				            info.animate({
								opacity: .5,
								height: 0
							}, time, 'swing', function () {
							    shown = false;
							    info.css('display', 'none');
							});
				        }
				        return false;
					};
					$('#nav').animate({height: 140, opacity: 1 }, 1000).animate({opacity: 1.0}, 2000, function () {
						hideMenu();	
					});
				});

		}); // End OnLoad
		
		
		

		//better colleges hover over
		$('#colleges li').each(function () {
		    var distance = 10;
		    var time = 500;
		    var hideDelay = 150;
		    var hideDelayTimer = null;
		    var beingShown = false;
		    var shown = false;
		    var trigger = $('h2 a', this);
		    var info = $('.popup', this).css('opacity', 0);

		    $([trigger.get(0), info.get(0)]).mouseover(function () {
		        if (hideDelayTimer) clearTimeout(hideDelayTimer);
		        if (beingShown || shown) {
		            // don't trigger the animation again
		            return;
		        } else {
		            // reset position of info box
		            beingShown = true;				
		           	info.css({
		                bottom: 53,
						zindex: 50,
		                display: 'block'
		            }).animate({
		                bottom: '+=' + distance + 'px',
		                opacity: 1
		            }, time, 'swing', function() {
		                beingShown = false;
		                shown = true;
		            });
		        }
		        return false;
		    }).mouseout(function () {
		        if (hideDelayTimer) clearTimeout(hideDelayTimer);
		        hideDelayTimer = setTimeout(function () {
		            hideDelayTimer = null;
		            info.animate({
		                bottom: '-=' + distance + 'px',
		                opacity: 0
		            }, time, 'swing', function () {
		                shown = false;
		                info.css('display', 'none');
		            });
		        }, hideDelay);
		        return false;
		    });
		});

	} // End if not IE6
	//////// Non Browser dependent code below



		// More about Devry
		$(function moreAbout() {
		    var distance = 10;
		    var time = 500;
		    var hideDelay = 100;
		    var hideDelayTimer = null;
		    var beingShown = false;
		    var shown = false;
		    var trigger = $('#more-about-call', this);
		    var info = $('#more-about', this).css('opacity', 0);

		    $([trigger.get(0), info.get(0)]).mouseover(function () {
		        if (hideDelayTimer) clearTimeout(hideDelayTimer);
		        if (beingShown || shown) {
		            // don't trigger the animation again
		            return;
		        } else {
		            // reset position of info box
		            beingShown = true;
					//tracking code
					dcsMultiTrack('DCS.dcsuri','DeVry.edu: Home  More About DeVry','WT.ti','DeVry.edu: Home  More About DeVry');
		           	info.css({
		                bottom: 36,
		                display: 'block'
		            }).animate({
		                bottom: '+=' + distance + 'px',
		                opacity: 1
		            }, time, 'swing', function() {
		                beingShown = false;
		                shown = true;
		            });
		        }

		        return false;
		    }).mouseout(function () {
		        if (hideDelayTimer) clearTimeout(hideDelayTimer);
		        hideDelayTimer = setTimeout(function () {
		            hideDelayTimer = null;
		            info.animate({
		                bottom: '-=' + distance + 'px',
		                opacity: 0
		            }, time, 'swing', function () {
		                shown = false;
		                info.css('display', 'none');
		            });

		        }, hideDelay);

		        return false;
		    });
		});

		//on select of iam hide keller a
		$("#iam-select").focus(function () {
			$('#colleges li#keller h2 a').hide();
		});
		//on de-deselect show keller a
		$("#iam-select").blur(function () {
			$('#colleges li#keller h2 a').show();
		});

		// Location script with XML
		$(function() { 
			// Get a parameter value from a querystring
			function getParam(name) {
				name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
				var regexS = "[\\?&]"+name+"=([^&#]*)";
				var regex = new RegExp( regexS );
				var results = regex.exec( window.location.href );
				if( results == null ) {
				  return false;
				  } else {
				  return results[1];
				  };
			};
			var city = getParam('city');  //console.log(city)
			var prog = getParam('program');  //console.log(prog);
			
			
			
			if (prog == "acct") {
				
				$(window).load(function () {
					if (!ie6) {
//						// run accounting
//						$('#slide-holder').cycle(2);
//						$('#ctrl-slider').stop().animate({"right": "222px"}, 600);
//						pauseShow();
//						dcsMultiTrack('DCS.dcsuri','DeVry.edu: Home  New Degree Tracks - Accounting ','WT.ti','DeVry.edu: Home  New Degree Tracks - Accounting');
					}
				});
				
	        }; // end if prog


			if (city) {

				$(window).load(function () {
					if (!ie6) {
						// run accounting
						$('#slide-holder').cycle(2);
						$('#ctrl-slider').stop().animate({"right": "222px"}, 600);
						pauseShow();
						dcsMultiTrack('DCS.dcsuri','DeVry.edu: Home  New Degree Tracks - Accounting City','WT.ti','DeVry.edu: Home  New Degree Tracks - Accounting City');
					}
				});
				
				$.ajax({
			    	type: "GET",
			    	url: "/resources/qw/locations.xml",
			    	dataType: "xml",
			    	success: parseXml
			  	});
				$('#location-default').after('<div id="location-data"></div>');

	        }; // end if city

			function parseXml(xml) {
				$(xml).find("location[param='" + city + "']").each(function() {
					formOutput = '';
					formOutput += '<h4>' + $(this).find("name").text() + '</h4>';
					formOutput += '<form action="#" method="get" id="form-locationCity" onSubmit="return selectLink(this);"><select name="iam" id="select-locationCity" class="select" ><option value="-1">Find one nearby</option>';
					$(this).find("campuses").find("campus").each(function() {
						formOutput += '<option value="' + $(this).attr('url') + '">' + $(this).text() + '</option>';
					});
					formOutput += '</select><input type="submit" value="Go" class="go-btn" /></form>';
					$("#location-data").append(formOutput);
					$("#location-default").css('display', 'none');
					// Locations graphic based on position
					pos = $(this).find("name").attr("pos");
					if(pos) {
						$("#location-data h4").css( {
							"text-indent": "-9999px",
							"background-image": "url('/resources/qw/img-home/sidebar-locations.gif')",
							"background-repeat": "no-repeat",
							"background-position": "0px " + pos + ""		
						});
					}					
				});						
			};
		});

}); // End JQuery


	// Explore the University Form Action
	function selectLink(oForm) {
		//alert(oForm.id);
		if(oForm.id == 'form-locationCity') {
			window.open (oForm.iam.value,"newwin");
		} else {
			if(oForm.iam.value.indexOf('http://') >= 0) {
				window.open (oForm.iam.value,"newwin");
			} else {
				document.location.href = oForm.iam.value;
			}
		}
		return false;
	};

	function popUp(url,width,height) {
		newwindow=window.open(url,'name','height=' + height + ',width=' + width);
		if (window.focus) {newwindow.focus()}
		return false;
	};

	// Live Chat Functionality
	var needValidate = false;
	var defaultVal2 = "Type your question here and click Start Chat.";
	function  openchatwindow(cbForm,windowName) {
		var res = true;
		var msg = document.getElementById("chat-field");
		if(needValidate){
			var validateMessage = "Before you start your chat, type in the following fields:\r\n ";
			if(msg.value.length==0 || msg.value==defaultVal2 ){
				validateMessage += "Your Question\r\n";
				res=false;
			}
			if(res==false){
				alert(validateMessage);
			}
		}
	    var formurl = cbForm.action;
	    if(formurl.indexOf('?')==-1)
	        formurl += '?';
	    var elemCol = cbForm.elements;
	    for(var ie=0; ie<elemCol.length; ie++){
	        var et = elemCol[ie].type;
	        if(et=="text" || et=="hidden" || et=="radio" || et=="textarea"){
	            formurl += elemCol[ie].name + "=" + escape(elemCol[ie].value) + "&" ;
	        }
	    }
		if(res==true)
			dcsMultiTrack('DCS.dcsuri','DeVry.edu: Home Chat Live Enter','WT.ti', 'DeVry.edu: Home Chat Live Enter');
			window.open(formurl, windowName,'width=475,height=400,resizable=yes');
		return res;
	};
