/*!
 * FUNÇOES
 */
$(document).ready(function() {
    $(".topMenuAction").click( function() {
        if ($("#openCloseIdentifier").is(":hidden")) {
            $("#slider").animate({
                marginTop: "-340px"
                }, 500 );
            $("#topMenuImage").html('<img src="http://www.mediaminds.pt/images/bt_orcamento.png"/>');
            $("#openCloseIdentifier").show();
        } else {
            $("#slider").animate({
                marginTop: "0px"
                }, 500 );
            $("#topMenuImage").html('<img src="http://www.mediaminds.pt/images/bt_orcamento_x.png"/>');
		
			/* RESET FORMULARIO */
			$(':input','#aspnetForm')
 			.not(':button, :submit, :reset, :hidden')
 			.val('')
 			.removeAttr('checked')
 			.removeAttr('selected');
			/* FIM RESET FORMULARIO */

            $("#openCloseIdentifier").hide();
        }
    }); 
});

/*!
* ORBIT
*/

$(window).load(function() {
	$('#featured').orbit({
     animation: 'horizontal-push',		// fade, horizontal-slide, vertical-slide, horizontal-push
     animationSpeed: 800,				// how fast animtions are
     timer: false,						// true or false to have the timer
     advanceSpeed: 4000,				// if timer is enabled, time between transitions 
     pauseOnHover: true,				// if you hover pauses the slider
     startClockOnMouseOut: true,		// if clock should start on MouseOut
     startClockOnMouseOutAfter: 0, 	// how long after MouseOut should the timer start again
     directionalNav: true,				// manual advancing directional navs
     captions: false,					// do you want captions?
     captionAnimation: 'fade',			// fade, slideOpen, none
     captionAnimationSpeed: 800,		// if so how quickly should they animate in
     bullets: false,					// true or false to activate the bullet navigation
     bulletThumbs: false,				// thumbnails for the bullets
     bulletThumbLocation: '',			// location from this file where thumbs will be
     afterSlideChange: function(){}		// empty function 
});	
});

/*!
* DIV SCROOL
*/
$(window).load(function() {
	$("div#logoParade").smoothDivScroll({
	autoScroll: "always",
	autoScrollDirection: "endlessloopright",
	autoScrollStep: 1,
	autoScrollInterval: 50
	});
// Logo parade
	$("div#logoParade").bind("mouseover", function() {
	$(this).smoothDivScroll("stopAutoScroll");
	}).bind("mouseout", function() {
	$(this).smoothDivScroll("startAutoScroll");
	});
});

/*!
* VALIDADOR
*/
jQuery(document).ready(function(){
// binds form submission and fields to the validation engine
jQuery("#formulario_orcamento").validationEngine();
jQuery("#subscrever_nl").validationEngine();
});
            
/**
*
* @param {jqObject} the field where the validation applies
* @param {Array[String]} validation rules for this field
* @param {int} rule index
* @param {Map} form options
* @return an error string if validation failed
*/
function checkHELLO(field, rules, i, options){
if (field.val() != "HELLO") {
// this allows to use i18 for the error msgs
return options.allrules.validate2fields.alertText;
}
}

function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}


/*!
* SCROOL
*/
$().ready(function() {
		var $scrollingDiv = $("#scrollingDiv");
 
		$(window).scroll(function(){			
			$scrollingDiv
				.stop()
				.animate({"marginTop": ($(window).scrollTop() + 0) + "px"}, "fast" );			
		});
	});

/*!
* TABS
*/
// perform JavaScript after the document is scriptable.
$(function() {
	// setup ul.tabs to work as tabs for each div directly under div.panes
	$("ul.tabs").tabs("div.panes > div", {effect: 'slide', history: true});
});
