jQuery(document).ready(function($) {

	function matrixFadeIn() {
		$("#introduction img.hdr01").fadeIn( 1400 ,
			function() {
				$("#introduction img.hdr02").fadeIn( 1140,
					function() {
						$("#introduction img.hdr03").fadeIn( 1020,
								function() {
								$("#introduction img.hdr04").fadeIn( 760 );
								$("#introduction img.hdr05").fadeIn( 760,
										function() {
											$("#introduction img.hdr06").fadeIn( 600 );
										}
								);
							}
						);
					}
				);
			}
		);
	}

	
	var findParagonCookie = document.cookie.indexOf("ParagonLoaded")
	//alert(findParagonCookie);

	if ( findParagonCookie == -1 ) {	
		//alert("alert01");
		document.cookie = "ParagonLoaded";
		matrixFadeIn();
	} else {
		//matrixFadeIn();
		//document.cookie = "ParagonLoaded";
		//alert(findParagonCookie);
		$("#introduction img.hdr01, #introduction img.hdr02, #introduction img.hdr03, #introduction img.hdr04, #introduction img.hdr05, #introduction img.hdr06").css({ "display" : "block" });
	}


	


	/* homepage news rotator */

	function randomModules() {

		var totalNumberOfMods = $("#rotating-mods div.rotate-mod").size();
		for ( initialNumberOfMods = 0; initialNumberOfMods <= totalNumberOfMods; initialNumberOfMods++ ) {

				//alert(initialNumberOfMods);
				//alert($("#extra_news div.rotate-mod:eq("+initialNumberOfMods+")").text());

			if ( $("#rotating-mods div.rotate-mod:eq("+initialNumberOfMods+")").text() == "" ) {

				//alert($("#extra_news div.rotate-mod:eq("+initialNumberOfMods+")").text());
				var modsWithContent = initialNumberOfMods;
				//alert( Math.min( 1, Math.round(Math.random()*(modsWithContent)) ) );
				//alert(Math.floor(Math.random()*modsWithContent));
				$("#rotating-mods div.rotate-mod:eq("+ Math.floor(Math.random()*modsWithContent) +")").css({ "display" : "block" });

				return

			} 

		}

	}



	if ( $("body").attr("id") == "home-page" || $("body").attr("class") == "subpage" ) {
		randomModules();
	}

	//alert($("#rotating-mods").width());
	//{global_content name='news_mod'}


	if ( $("#sidebar #rotating-mods").height() > 0 && $("#sidebar #news-mod").height() > 0  ) {
		$("#rotating-mods").addClass("addRule");	
		$("#rotating-mods div.rotate-mod").css( {  "padding-bottom" : "18px"  });	

	}

	if ( $("#sidebar #news-mod").height() > 0  ) {
		$("#news-mod").addClass("addRule");	
	}





	var numberOfStaticMods =  $("#sidebar #static-mods div.static-mod").size();

	
	for ( var i = 0; i < numberOfStaticMods; i++ ) {
		//alert(  $("#sidebar #static-mods div.static-mod:eq("+ i +")").height()  );
		if ( $("#sidebar #static-mods div.static-mod:eq("+ i +")").height() > 0 ) {
			$("#sidebar #static-mods div.static-mod:eq("+ i +")").css({ "padding-top" : "12px" , "padding-bottom" : "6px" });
			//$("#sidebar #static-mods div.static-mod:eq("+ i +")").addClass("addRule");
		}

	}




	var numberOfBlueStaticMods =  $("#sidebar #static-mods div.static-blue-mod").size();


	for ( var i = 0; i < numberOfBlueStaticMods; i++ ) {

		contentLength = $("#sidebar #static-mods div.static-blue-mod:eq("+ i +")").html();

		//alert( contentLength.length );

		if ( contentLength.length <= 0 ) {

			//do nothing

		} else {

			$("#sidebar #static-mods div.static-blue-mod:eq("+ i +")").css({ "display" : "block" , "margin" : "1.3em auto 0.8em auto" });
			var content = $("#sidebar #static-mods div.static-blue-mod:eq("+ i +")").html();
			headerContent = content.slice ( 4 , (  content.search( "/") - 1 ) );
			boxContent = content.slice ( ( content.search ("/") + 4 ) , content.length );
			//alert(headerContent)
			//alert(boxContent)
			$("#sidebar #static-mods div.static-blue-mod:eq("+ i +")").html('');
			$("#sidebar #static-mods div.static-blue-mod:eq("+ i +")").html('<h4>'+headerContent+'</h4><div class="box_content">'+boxContent+'</div>');
			//$("#sidebar #static-mods div.static-blue-mod:eq("+ i +")").html('<h4>'+headerContent+'</h4>');
		}

	}


	var homePage = [];


	$("#home-page #whats_new div.post a").append("&nbsp;").attr("target" , "_blank");

    homePage.linkLength = $("#home-page #whats_new div.post ul li a").text().length;
	homePage.postLength = $("#home-page #whats_new div.post ul li").text().length;
	homePage.post = $("#home-page #whats_new div.post ul li").text().slice( homePage.linkLength , homePage.postLength );
	homePage.postTrimmed = $("#home-page #whats_new div.post ul li").text().slice( homePage.linkLength , homePage.linkLength + 160 );


	$("#home-page #whats_new div.post ul li span").text(homePage.postTrimmed + "\u2026");
	$("#home-page #whats_new div.post ul li a").attr("target" , "_blank");

	/* start subpage nav generator */

	if ( $("body").hasClass("subcontent") ) {

		// insert subnav
		$("h2.page_header").after('<ul id="subpage_nav"></ul>');
		// get items
		numOfSubItems = $("div.subitem").size();

		//create subnavigation

		for ( var i = 1; i <= ( numOfSubItems + 1 ); i++ ) {

			if ( i == 1 ) {
				$("#subpage_nav").append('<li id="overview" class="on"><a href="#">Overview</a></li>');

			} else {
				headerText = $("div.subitem:eq(" + ( i - 2 ) + ") h3:first-child" ).text();
				$("#subpage_nav").append('<li id="subcontent0'+ ( i -1 ) +'"><a href="#">' + headerText + '</a></li>');
				$("div.subitem:eq("+( i - 2 )+")").addClass( "subcontent0"+( i -1 ) +"" );

				if ( i == ( numOfSubItems + 1 ) ) {
					$("div.overview").addClass("subitem");	
				}				

			}

		}

	}



	$("#subpage_nav li").click(

		function () {

			$("#subpage_nav li").removeClass("on");
			$(this).addClass("on");
			var navId = $(this).attr("id");
			$("div.subitem").slideUp( 300 );
			$("div."+ navId +"").slideDown(750);

		}

	);


	$("#subpage_nav").css({ "display" : "block" });


	/* end subpage nav generator */	


	$("#search input.search_button, #sign_up fieldset input.submit_button").val('');
	$("#search, #sign_up form").css({ "display" : "block" });


	$("#main_nav > li").hover(

		function() {
			var NavId = $(this).attr("id");
			$("#main_nav > li#"+ NavId +" > ul").fadeIn(200);
			$(this).addClass("on");
		},

		function() {
			var NavId = $(this).attr("id");
			$("#main_nav > li#"+ NavId +" > ul").fadeOut("fast");
			$(this).removeClass("on");
		}

	);


	$("#main_nav > li > ul > li").hover(

		function() {
			$(this).addClass("on");
			$("#main_nav > li.on > ul > li.on > ul").fadeIn(200);
		},

		function() {
			$("#main_nav > li.on > ul > li > ul").fadeOut("fast");
			$(this).removeClass("on");
		}

	);



	$("#main_nav li ul li").each(

		function() {
			//var listId = $(this).attr("id");
			//listId = listId.replace( ' ' , '').replace( ' ' , '').replace( ' ' , '').replace( '/' , '').replace( ';' , '').toLowerCase();
			//$(this).attr( "id" , listId );
		}								 

	);






	$("#paragon-matrix #info div div p:last-child").css( { "position" : "absolute", "left" : "-99999em"});



	$("#paragon-matrix #life-cycle_nav dd ul li:nth-child(1) a").css( { "top" : "30px", "left" : "2px" , "width" : "98px" , "height" : "40px" });
	$("#paragon-matrix #life-cycle_nav dd ul li:nth-child(2) a").css( { "top" : "122px", "left" : "2px" , "width" : "98px" , "height" : "40px" });
	$("#paragon-matrix #life-cycle_nav dd ul li:nth-child(3) a").css( { "top" : "202px", "left" : "2px" , "width" : "98px" , "height" : "40px" });

	$("#paragon-matrix #capabilities_nav dd ul li:nth-child(1) a").css( { "top" : "0px", "left" : "0px" , "width" : "283px" , "height" : "28px" , "background-position" : "0px 0px" });
	$("#paragon-matrix #capabilities_nav dd ul li:nth-child(2) a").css( { "top" : "0px", "left" : "288px" , "width" : "283px" , "height" : "28px" , "background-position" : "0px 0px" });



	$("#paragon-matrix #capabilities_nav dd ul li a").hover(

		function() {
			$(this).css({ "background-position" : "0px -28px" });
		},

		function() {
			$(this).css({ "background-position" : "0px 0px" })		
		}		

	);



	var numOfLinks = $("#paragon-matrix #life-cycle_nav dd ul li").size();



	for ( var i = 1 ; i <= numOfLinks ; i++) {
		$("#paragon-matrix #life-cycle_nav dd ul li:nth-child("+i+") a").addClass("positon0"+i+"");
	}


	$("#paragon-matrix #life-cycle_nav dd ul li a").hover(

		function() {	
			linkPosition = $(this).attr("class").charAt( ($(this).attr("class").search("0") + 1) );
			$("#paragon-matrix #life-cycle_nav dd").css({ "background-position" : "-"+ (104 * linkPosition ) +"px 0px" });
			$(this).css({ "cursor" : "text" })		
		},

		function() {
			$(this).css({ "cursor" : "auto" })
		}		

	);



	$("#paragon-matrix #info div").hide();
	$("#paragon-matrix #info div.intro").show();


	var arrowID = "";
	var lifeCycleInfo = true;


	if ( lifeCycleInfo = true ) {
		$("#info #life-cycle").show();
	}


	$("#info #life-cycle div.flagged").show();



	$("#life-cycle_nav a").hover(

		function () {

			if ($(this).hasClass("flagged")) {
				return false
			} else {
				$("#paragon-matrix #info #life-cycle div.flagged div").hide();
				$("#life-cycle_nav a").removeClass("flagged"); 
				$(this).addClass("flagged");  //alert($(this).attr("rel"));
				lifeCycleInfo = true;
				$("#paragon-matrix #info #life-cycle").show();
				arrowID = $(this).attr("href").replace( /#/ , ""); //alert(arrowID);		
				$("#paragon-matrix #info #life-cycle div.flagged").slideUp(150 ,

					function () {
						$("#paragon-matrix #info #life-cycle #"+arrowID).addClass('flagged').slideDown(250 ,
							function () {
								$("#paragon-matrix #info #life-cycle div.flagged div").slideDown();
							}
						);
					}	

				).removeClass("flagged");	

			}

		},


			function () {

				lifeCycleInfo = false;
				 
		}

		
	  );





	$("#paragon-matrix").hover(

		function() {},
		
		function() {

				$("#paragon-matrix #life-cycle_nav dd").css({ "background-position" : "0px 0px" });
				$("#paragon-matrix #info #life-cycle div.flagged div").hide();
				$("#life-cycle_nav a").removeClass("flagged"); 
				$("#paragon-matrix #info #life-cycle").show();
				$("#paragon-matrix #info #life-cycle div.flagged").slideUp(20 ,
					function () {
						$("#paragon-matrix #info #life-cycle #introduction").addClass('flagged').slideDown(160 ,
							function () {
								$("#paragon-matrix #info #life-cycle div.flagged div").slideDown();
							}
						);
					}	
				).removeClass("flagged");	
				$("#paragon-matrix #info #life-cycle #introduction").addClass('flagged');	
		}
	);



	$("#sign_up input.textfield").focus(

		function() {
			$(this).val('');
			$(this).css({ "font-style" : "normal" , "color" : "#505050" });
		}
	);


});