jQ(document).ready(function(){
	
	/*
	-----------------------------------
	-- MODEFY THE GLOBAL NAVIGATION
	-----------------------------------
	*/
	countNav0 	= 0;
	countNav1 	= 0;
	
	/*sublevel 4*/
	jQ("#navcontainer li ul li ul li ul li ul").remove();
	
	/*sublevel 3*/
	if( jQ("#navcontainer li ul li ul li ul").length){
		jQ("#navcontainer li ul li ul li ul").clone().prependTo("#sidebar").attr({id:"side_sublevel3"});
		jQ("#navcontainer li ul li ul li ul").attr({id:"sublevel3"}).prependTo("#temp_container");	
	}

	/*sublevel 2*/
		
		/*go back link*/
		if( jQ("#navcontainer li ul li ul li.currentAncestor a").length){
			var TextLink = jQ("#navcontainer li ul li ul li.currentAncestor a").text();
			//jQ("#navcontainer li ul li ul li.currentAncestor a");
			jQ("#navcontainer li ul li ul li.currentAncestor").clone().prependTo("#sidebar ul#side_sublevel3").addClass("wayBack");
            jQ(".wayBack a").text("Overview");
		}

	if( jQ("#navcontainer li ul li ul").length){
		jQ("#navcontainer li ul li ul").clone().prependTo("#sidebarContainer").attr({id:"side_sublevel2"});
		jQ("#navcontainer li ul li ul").attr({id:"sublevel2"}).prependTo("#temp_container");	
	}
	
	/*sublevel 1*/
	if( jQ("#navcontainer li ul").length){
		jQ("#navcontainer li ul").prependTo("#subnav1");
	}

	/*last steps for navigation*/
	jQ("#subnav1 li").each(function () {
		if(jQ("a:contains('_')",this).length) {
			jQ(this).remove();
		}
	});
	
	/*
	-----------------------------------
	-- BREADCRUMB NAVIGATION
	-----------------------------------
	*/
	/*breadcrumb and global naviagtion*/
	jQ("#navcontainer li").each(function(){countNav0 = countNav0+1;});
	jQ("#subnav1 li").each(function(){countNav1 = countNav1+1;});
	
	if(countNav0 > 1) 
	{
		jQ("#navcontainer li:first").addClass("first");
		jQ("#navcontainer li:last").addClass("last");
	} else { 
		jQ("#navcontainer li:first").addClass("single"); 
	}
	
	if(countNav1 > 1) 
	{
		jQ("#subnav1 li:first").addClass("first");
		jQ("#subnav1 li:last").addClass("last");
	} else { 
		jQ("#subnav1 li:first").addClass("single"); 
	}
	
	/*breadcrumb*/
	jQ("#breadcrumbcontainer a:last").addClass("active");

	
	/*
	-----------------------------------
	-- SOME HELPER TO CLEAN THE CODE
	-----------------------------------
	*/
	
	jQ(".sideHeader:empty").remove();
	
	if(jQ("#side_sublevel3").length) { } else {
		if (jQ("#sidebar").is(":empty")) {
			jQ("#sidebar").remove();
		}
	}
	

	
	/*
	-----------------------------------
	-- HOVER ONLY FOR FRESHME
	-----------------------------------
	*/		
	jQ(".img-border_fm.link").each( function() {
		var text = jQ("a",this).attr("title");
		var height = jQ(".img-border_fm.link").height();
		
		jQ("a",this).attr("title","");

		jQ(this).append('<div class="hover_pad"><span>'+text+'</span></div>');
		jQ(".hover_pad",this).css({display:"block", opacity: "0"});
		jQ(this).hover(function () {
       		jQ(".hover_pad",this).stop().fadeTo(500, 1);
      	}, function () {
        	jQ(".hover_pad",this).stop().fadeTo(500, 0);
      	});

	});
	
	/*
	-----------------------------------
	-- LIST ONLY FOR FRESHME 
	-----------------------------------
	*/	
	if(jQ("#sidebar #sPTy_fm").length){
		var Content = jQ("#sidebar #sPTy_fm").text();
		var Content = Content.split(",");
		jQ("#sidebar #sPTy_fm").text("");
		jQ("#sidebar #sPTy_fm").prepend('<h3>Supported Page Types</h3><p>RapidWeaver ships with 10 powerful page types: those who are listed below are supported by the theme.</p><ul id="pageTypeList"></ul>');

		jQ.each(Content, function(i, val) {
			if(val == "blog") { var text = '<h3>Blog</h3><p>Start your own blog with podcasts.</p>'}
			if(val == "text") { var text = '<h3>Styled Text</h3><p>Format your text like a word processor.</p>'}
			if(val == "code") { var text = '<h3>Html Code</h3><p>Create HTML, XHTML, PHP, or any content.</p>'}
			if(val == "filesh") { var text = '<h3>File Sharing</h3><p>Put files, photos and documents online.</p>'}
			if(val == "contact") { var text = '<h3>Contact Form</h3><p>Get e-mails through an easy-to-use contact form.</p>'}
			if(val == "quicktime") { var text = '<h3>Quicktime</h3><p>Put films for friends, family and colleagues online.</p>'}
			if(val == "album") { var text = '<h3>Photo Album</h3><p>Publish your photos in a CSS gallery or as an Flash slideshow.</p>'}	
			if(val == "movie") { var text = '<h3>Movie Album</h3><p>Put films for friends, family and colleagues online.</p>'}
			
			
				
      		jQ("#sidebar #sPTy_fm #pageTypeList").append('<li><div class="icn"><img src="'+BaseUrl+'/0_fm_img_icn/'+val+'_32.png"/></div><div class="text">'+text+'</div><div class="clear">&nbsp;</div></li>');
    	});
	}
	
});
