/*
/*	Dynamic design functions and onLoad events
/*	----------------------------------------------------------------------
/* 	Creates added dynamic functions and initializes loading.
*/
//---- google analitycs for button submits
function CallPage( $page, $pageAnalitycs ){ //alert( "CallPage("+ $page +","+ $pageAnalitycs+");" );
	/*pageTracker._trackPageview($pageAnalitycs);
	if( $page ){
		location.href='./'+ $page +'/';
	}
	*/
}

// ======================================================================
//
//	On document ready functions
//
// ======================================================================

jQuery(document).ready(function() {
	
	//header menu
	$j("ul.sf-menu").find('li:first').css('margin-left','122px');
	$j("ul.sf-menu li").each( function(){ 
		$j(this).find('li:last').addClass('last');
	});
	
	//footer menu
	$j("#menu-footer ul").find('li:last').addClass('last');
	
	// search current-menu-item in sub-menus
	var $arr = new Array();
	$arr = $j("ul.sf-menu > li").find('.current-menu-item');
	if( $arr.length > 0 ){ //takes first element and add class name
		$j( $arr[0] ).parent().parent().addClass("current-menu-item")
	}
	
	// initialise main-menu (jQuery superfish plug-in)
	// -------------------------------------------------------------------
	
		$j('ul.sf-menu').superfish({  		// initialize superfish
			pathClass:  'current-menu-item',
			delay:       2400,                            // one second delay on mouseout 
            animation:   {height:'show'},  	// fade-in and slide-down animation 
            speed:       'slow',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false
		});
	
	// initialise slide show (Cycle plugi-n)
	// -------------------------------------------------------------------
		//header
	$j('#slide-header #ss-header').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 5000
	});
	
	if( $is_load == "home" ){
		//home
		$j('#slide-home .slideshow').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			next: '#arrow_next',
			prev: '#arrow_prev',
			pager:  '#nav',
			slideExpr: 'img'
		});
		// initialise scrollbar (tinyscrollbar plugi-n)
		$j('#sbar').tinyscrollbar();
	}
	if( $is_load == "single" ){
		// the default action of the event will not be triggered. 
		$j( '.gallery-item .gallery-icon a').click(function(event) {
			event.preventDefault();
		});
	}
	
	
	/* tout's */
	var $form_a1 ="#formSuscribe_a1";
	jQuery( $form_a1 + " :input.textInput").val("");
	jQuery.metadata.setType("attr", "validate");
	// form validation
	// -------------------------------------------------------------------
	jQuery( $form_a1 ).validate({
		messages: { 
			a1_email: { required: "*", email:"*" },
			a1_mailing: { required: "*" }
		},
		submitHandler: function(form) {
			// form is valid, submit it
			ajaxSendForm(form, $form_a1 , 'send-entertowin.php' );
			return false;
		}
	});
	
	var $form_a2 ="#formSuscribe_a2";
	jQuery( $form_a2 + " :input.textInput").val("");
	jQuery.metadata.setType("attr", "validate");
	// form validation
	// -------------------------------------------------------------------
	jQuery( $form_a2 ).validate({
		messages: { 
			a2_email: { required: "*", email:"*" },
			a2_mailing: { required: "*" }
		},
		submitHandler: function(form) {
			// form is valid, submit it
			ajaxSendForm(form, $form_a2 , 'send-textupdates.php' );
			return false;
		}
	});
	
});
function Gallery_single(){	
	if( $is_load == "single" ){
			//get id of [gallery]
		var $id_gallery = "#ss-single #ss-holder #"+$j('#ss-single #ss-holder div:first').attr('id');
		// reset styles in wp [gallery]
		$j( $id_gallery ).css('margin','0px').css('width','100%').css('height','100%').css('position','relative');
		$j( $id_gallery + ' .gallery-item').css('margin','0px').css('width','100%');
		$j( $id_gallery + ' img').css('border','0px solid red');
		
			// the default action of the event will not be triggered. 
		$j( $id_gallery + ' a').click(function(event) {
			event.preventDefault();
		});			
		
		
		
			//add navbar and arrow(s)
		var $innerHtml = '<div id="ss-nav"><div id="nav"></div></div>';
		$innerHtml += '<div class="clear"></div>';
		$innerHtml += '<a href="#" id="arrow_prev"><span> + </span></a>';
		$innerHtml += '<a href="#" id="arrow_next"><span> - </span></a>';
		
		$j( $id_gallery ).prepend( $innerHtml );
		
			//set plugin
		$j( $id_gallery ).cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			next: '#arrow_next',
			prev: '#arrow_prev',
			pager:  '#nav',
			slideExpr: 'dl'
		});
	}
}	
	
function formVolunteer_info() { //alert("formVolunteer_info");
	/**/
	var $form ="#formVolunteer_info";
	jQuery( $form + " label.overlabel").overlabel();
	jQuery( $form + " :input.textInput").val("");
	jQuery.metadata.setType("attr", "validate");
	// form validation
	// -------------------------------------------------------------------
	jQuery( $form ).validate({
		messages: { 
			name: { required: "*" },
			adress: { required: "*" },
			city: { required: "*" },
			state: { required: "*" },
			phone: { required: "*" },
			cell: { required: "*" },
			email: { required: "*", email:"*" }
		},
		submitHandler: function(form) { //alert( "isValid" );
			// form is valid, submit it
			ajaxSendForm(form, $form , 'send-volunteer_info.php' );
			return false;
		}
	});
};

function formAccreditation() { //alert("formAccreditation");
	/**/
	var $form ="#formAccreditation";
	jQuery( $form + " label.overlabel").overlabel();
	//jQuery( $form + " :input.textInput").val("");
	jQuery.metadata.setType("attr", "validate");
	// form validation
	// -------------------------------------------------------------------
	jQuery( $form ).validate({
		messages: { 
			ac_name: { required: "*" },
			ac_adress: { required: "*" },
			ac_city: { required: "*" },
			ac_state: { required: "*" },
			ac_phone_office: { required: "*" },
			ac_email: { required: "*", email:"*" },
			ac_agreement: { required: "*" }
		},
		submitHandler: function(form) { //alert( "isValid" );
			// form is valid, submit it
			ajaxSendForm(form, $form , 'send-accreditation.php' );
			return false;
		}
	});
};

// ======================================================================
//	Proceses functions
// ======================================================================
// -------------------------------------------------------------------     
function ajaxSendForm(theForm, $idForm, $file) { //alert( "ajaxSuscribe("+ theForm +", "+ $idForm +", "+ $file +")"); return; 
	jQuery($idForm+' button').hide();
	jQuery($idForm+' #loader').fadeIn();	
	var formData = jQuery(theForm).serialize(),
		$URL = jQuery( $idForm+' #URL').val() + $file,
		note = jQuery( $idForm+'-msg'),
		result;
	note.hide();
	//alert( $URL +", "+formData ); return;
	jQuery.ajax({
		type: "POST",
		url: $URL,
		data: formData,
		success: function(response) { //alert('response' + response);
			jQuery($idForm+' #loader').hide();
			var $data = response.split(',');
			if ( $data[0] == 1 ) { //alert('$data[0]='+$data[0]);
				jQuery(theForm).animate({opacity: 0},'fast',function(){ 
					jQuery(theForm).remove();
					note.fadeIn();
				});
			}else{ //alert("else="+response);
				jQuery($idForm+' button').fadeIn();
				var i = setInterval(function() {
					if ( jQuery($idForm+' button').is(':visible') ) {
						result = response;
						note.html(result);
						note.fadeIn('slow');
						clearInterval(i);
					}
				}, 40);
			}
		},
		error:function( event,request, settings ){ 
			alert( event+", <br>"+request+",<br>"+settings );
		}
	});
	return false;
}


