// Main js doc that is used through out the site.




function openVWWindow(userObj,action){
	//check the user id is set
	if(userObj.id.length > 0){
		//alert("TEST: Is logged in");	
		switch(action){
			case 'order':
				$().popupwindow();
				break;
			case 'order_process':
				break;
			default:
				break;
		}
	
	}else{
		//alert("TEST: not logged in");
	
	}
		
	
	
}



jQuery.logger = function(message) {
  if(window.console) {
     console.debug(message);
  } else {
   //  alert(message);
  }
};
		//for text folding triggerd by h1 above the text to hide
		//text to hide is div.TextToFoldDiv
		//the h1 and div.TextToFoldDiv are in div.TextFoldingDiv
		//h1 toggles the div.TextToFoldDiv 
		$(document).ready(function(){
			$(".TextToFoldDiv").hide();
			$(".TextFoldingDiv").find("h1").click(function(){
				//will be closing all open .TextFoldingDiv
				//so get a flag for the status of the current clicked item's TextFoldingDiv
				//then the if below can tell if it was already open so this click
				// must have been to close it.
				var textIsVisible = $(this).parent().find(".TextToFoldDiv").is(':visible');
				//close all open text divs
				$(".TextToFoldDiv").slideUp('normal');
				//remove the class that made any of the h1 red
				$(".TextFoldingDiv").find("h1").removeClass("RedText");
				//only toggling if the text was not already open
				if(textIsVisible == false){
					//$(this).next(".TextToFoldDiv").slideToggle(100);
					$(this).next(".TextToFoldDiv").slideDown('normal');
					$(this).toggleClass("RedText");
				}
			})
		});
		
		$(document).ready(function(){
			//when page loads hide all divs on left col that have the .leftColumnContentToFold class
			$(".leftColumnContentToFold").hide();
			$(".firstLeftContentToFold").show();
			//s$(".open-at-load").show();
			
			
			//add click handler for all buttons in left column that have ..leftColumnFoldingDivButton class
			$(".leftColumnFoldingDivButton").click(function(){
					//loop each button make sure it is not red anymore
				$(".leftColumnFoldingDivButton").each(function(){
					var src = $(this).attr("src").replace(/_red/,"");
					$(this).attr("src", src);
				});
				//if current button clicked has it content already open
				//then the click must hve been to close it so we need to not turn it red
				var thisBtnTextIsVisible = $(this).parent().find(".leftColumnContentToFold").is(':visible');
				if( thisBtnTextIsVisible == true){
					$(this).attr("src" ,$(this).attr("src").replace(/_red/,"")) 	
					$(this).next(".leftColumnContentToFold").slideUp(50);
				}else{
					$(".leftColumnContentToFold").slideUp('noramal'); //close everybody
					$(this).next(".leftColumnContentToFold").slideDown(100);
					$(this).attr("src",$(this).attr("src").replace(/.gif/,"_red.gif"));
				}
			})
			
			$("#poll_div").load("/community/deliverPoll.php",{},setPoll);
			
			
		});
		
/******************
** for poll
*/

function setPoll(responseText, textStatus, XMLHttpRequest){
$("form#poll-view-voting").submit(function(){  
//$(this).attr("action",'#');										   
var choice_val = $('input[name=choice]:checked').val();
if(typeof(choice_val) =="undefined"){
return false;
}
 


$.ajax({  
  type: "POST",  
  //url: "/community/deliverPoll.php",  
  url: "/community/savePoll.php",  
  data: $("#poll-view-voting").serialize(),  
  success: function(response) { 
 	   $("#poll_div").load("/community/deliverPoll.php");
  }  
});  



return false;
})
}
;


