/*
	Copyright 2009 AG Coding
	www.coding.lt
*/

// Main options [[
    
	// jQuery set the no conflict param ( now the "$" -  function not working and works only - "jQuery" ). 
	jQuery.noConflict();
// ]]


// Main menu functions [[
/*
	MAIN - header menu with subs.
*/
	var prevSubID	= new String("none");
	var prevParID	= new String("none");
	var selParentID	= new String("none");
	    
	var MenuTimeout;
	    
	var menu_subs	= new Array(); 
	    
	function showSubs(parentID) {
		    
		needSubID	= '#subs_'+parentID;
		parentID	= '#parent_'+parentID;
		speed		= 1500;
	    
		// Back to the original (user selected possition) [[
			clearMenuTimeOut();
		// ]]
		    
		if (jQuery(needSubID).is(":hidden")) {
		    
			if ( prevSubID != 'none' && prevSubID != needSubID ) {
				//alert(prevSubID);
				//jQuery(prevSubID).animate({"left": "+=50px"}, "slow");
				//jQuery(prevSubID).slideUp(100);
				jQuery(prevSubID).fadeOut();
	
				//jQuery("#headerMenu").animate({ marginTop: 25 }, 800 );
	    
			}
		    
			//jQuery(needSubID).slideDown('slow');
			jQuery(needSubID).fadeIn('slow');
				
			//alert(parentID);
			//jQuery(needSubID).show();
			//jQuery(needSubID).animate({"display": ""}, "");
			// jQuery("#headerMenu").animate({ marginTop: 0 }, 500 );
				 
			prevSubID = needSubID;
				
			existSubs = true;
			
		} else {
			//jQuery(needSubID).slideUP('slow');
			existSubs = true;
		}
		    
		// Parents [[
			if (jQuery(needSubID).length == 0 ){
				jQuery("#headerMenu").animate({ marginTop: 26 }, 500 );
				//jQuery("#headerMenu").animate({ height: 23 }, 500 );
				//jQuery("#headerMenu").css('backgroundImage','url()'); 
				//jQuery("#headerMenu").animate({backgroundPosition: '(500px 150px)'}) 
				jQuery(prevSubID).fadeOut(); // hide the prev subs block 
				//alert('!!!');
			} else {
				jQuery("#headerMenu").animate({ marginTop: 0 }, 500 );
				//jQuery("#headerMenu").animate({ height: 50 }, 500 );
				//jQuery("#headerMenu").animate({backgroundPosition: '(0px 0px)'}) 
			}
			    
			    
			    
			if ( prevParID != 'none' && prevParID != parentID  ) {
				jQuery(prevParID).removeClass("selected");
			} 
			
			jQuery(parentID).addClass('selected');
			prevParID = parentID;
		// ]]
	    
	}
	
	// Back to the original (user selected possition) [[
	function clearMenuTimeOut() {
		clearTimeout(MenuTimeout);
		MenuTimeout	=	setTimeout("showSubs('"+selParentID+"')",5000);
	}
	// ]]
	
// ]]

// Simple tabs functions [[
	
	// Show/Hide the block [[
		function displayBlcokByID ( blockID ){
			
			jqBlockID	=	'#'+blockID;
			
			if ( jQuery(jqBlockID).is(":hidden") ) {
				jQuery(jqBlockID).slideDown('slow');
			} else {
				jQuery(jqBlockID).slideUp('slow');
			}
		}
	// ]]
	
// ]]

// Get the anchor id by anchor name [[
	function getIdByAnchor() {
		var id = location.hash.replace('_anchor','');
		var id = location.hash.replace('#','');
		return id;
	}
// ]]

// Redirect to the spesifed page [[
	function redirect(to) {
		window.location = to;
	}
//]]

// Before submit the form, show the question [Y/N]. [[
	function getPermission(form,message){
	   if(confirm(message)){
		  sumbit(form);
	   }
	}
// ]]

// Help hint functions [[
	var HelpTimeout;
	var helpParentID	= new String("none");
	
	function showHelp (object,blockID,param) {
		
		if ( blockID != '' ) {
			object = document.getElementById(blockID);
		}
		jsBlockID			= "#"+jQuery(object).attr("id");	
		jsChildrenTextBlock = "div[rel='helpBlockText']";
		
		
		jQuery(document).ready(function(){
			
			if ( helpParentID != jsBlockID ) {
			// if not selected the same block
			
				// Hide previus help block [[
				if ( helpParentID != 'none' ) {
					jQuery(helpParentID+' > '+jsChildrenTextBlock).hide();
				}
				// ]]
			}
			
			if ( !jQuery(jsChildrenTextBlock,object).is(':animated') ) {
				 
				
				if (jQuery(jsChildrenTextBlock,object).is(":hidden")) {
				// if text block is hidden
						
						// show help info block
						jQuery(jsChildrenTextBlock,object).fadeIn('slow');
						
							
						if ( param != 'click' ) {
						// if not clicked, auto hide the block 	
							cleaerTimerHelp();
						}
						
						// update tge value 
						helpParentID = jsBlockID;
					
						
				} else {
				// hide the info block
					jQuery(jsChildrenTextBlock,object).fadeOut('slow');
					//jQuery(jsChildrenTextBlock,object).hide();
						
				}
				 
				
			}
			
		});
	}
	
	function hideAllHelps() {
		jsChildrenTextBlock = "div[rel='helpBlockText']";
		jQuery(jsChildrenTextBlock).fadeOut('slow');
	}
	
	function cleaerTimerHelp(){
		clearTimeout(HelpTimeout);
		HelpTimeout	=	setTimeout("hideAllHelps()",10000);
	}
// ]]
// Last works preview  functions [[

	/*
		Function fo titul pgae small gallery ( users works preview );
		(c) 2009 coding.lt
	*/
	var AllTitulImgs        =  Array(); // All images containers ID.
	var TitulImgsTimeout;   // timeOut var 
	var prevTitulImgID	= new String("none");
	var elCount             = new Number(0);
	var ShowNowImgNumber    = new Number(0);
	
	function titulChangeImage(NowID) {
		
		imageNowID	=	'#titulImg_'+NowID;
		
		if ( imageNowID != prevTitulImgID  ) {
			
			
			
			// Hide the previus image [[
			if ( prevTitulImgID != 'none'  ) {
				//jQuery(prevTitulImgID).fadeOut('slow');
				jQuery(prevTitulImgID).hide();
			}
			// ]]
			
			// Display the selectdet image
			jQuery(imageNowID).fadeIn('slow');
			
			
			// update the variable
			prevTitulImgID	=	imageNowID;
			
			clearTitulImgsTimeOut(); // Clear time out And Start Auto Show.
		}
	}
	
	function autoChenageTitulImage(){
	// Auto change images step by step
	
		elCount = AllTitulImgs.length; // All count of the images 
		
		if ( ShowNowImgNumber < elCount ) {
		// only if this image exist in array
		
			titulChangeImage(AllTitulImgs[ShowNowImgNumber]); // change image
			ShowNowImgNumber++; // next image number 
			
		} else {
			ShowNowImgNumber = 0; // go to first image, start. 
		}
		
		clearTitulImgsTimeOut(); // clear timeoute and set new.
	}
	
	function clearTitulImgsTimeOut() {
		clearTimeout(TitulImgsTimeout);
		TitulImgsTimeout	=	setTimeout("autoChenageTitulImage()",5000);
	}
	
	jQuery(document).ready(function(){
		autoChenageTitulImage(); // start the Auto image rotation 
	});
// ]]