/**
* First page slideshow
*/
var lastDescriptionID = 1;
function changeInfo(descriptionID){
    $('bullet_'+lastDescriptionID).removeClassName('navBulletActive');
    $('bullet_'+descriptionID).addClassName('navBulletActive');    
    new Effect.Fade('description_'+lastDescriptionID, { from: 1, to: 0, afterFinish: 
        function(){
            $('description_'+descriptionID).appear();
        }
    });
    lastDescriptionID=descriptionID;
}

var totalDescriptions = 3;
var autoChange = 1;
function autoChangeInfo(){
    if (autoChange==1){
        if (lastDescriptionID==totalDescriptions){
            var nextID = 1;
        }
        else {
            var nextID = lastDescriptionID+1;
        }
        changeInfo(nextID);
        setTimeout("autoChangeInfo()", 7000);
    }
}
/**
* Contact
*/
function contactForm(){
    var contactName = $('contactName').value;
    var contactEmail = $('contactEmail').value;
    var contactText = $('contactText').value;
    var err;
    if (!contactName){
        Effect.Shake('contactName', {duration: 1});
        err=1;
    }
    if (!contactEmail || !validateEmail(contactEmail) ){
        Effect.Shake('contactEmail', {duration: 1});        
        err=1;
    }
    if (!contactText){
        Effect.Shake('contactText', {duration: 1});
        err=1;
    }    
    if (!err){
        new Ajax.Request('/Page/Contact/', {
            method: 'post',
            postBody: 'contactName='+escape(contactName)+'&contactEmail'+escape(contactEmail)+'&contactText='+escape(contactText),
            onSuccess: function(transport) {
                alert('Successfully sent!');
                
                $('contactName').value='';
                $('contactEmail').value='';
                $('contactText').value='';
            }
        });
    }
}

function validateEmail( strValue) {
    var objRegExp  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    return objRegExp.test(strValue);
}

/**
* Video BOX
*/
function lightVideo(video){

    var objBody = $$('body')[0];
    
	objBody.appendChild(new Element('div',{id: 'videoOverlay'}));
    $('videoOverlay').hide();
    objBody.appendChild(new Element('div',{id: 'videoBox'}));
    $('videoBox').hide();
    $('videoBox').appendChild(new Element('div',{id: 'videoContainer'}));
    $('videoContainer').hide();

    var arrayPageSize = getPageSize();
    $('videoOverlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });

    new Effect.Appear('videoOverlay', { duration: 0.2, from: 0.0, to: 0.5 });
    
    var arrayPageScroll = document.viewport.getScrollOffsets();
    var boxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
    var boxLeft = arrayPageScroll[0];
    $('videoBox').setStyle({ top: boxTop + 'px', left: boxLeft + 'px' }).show();
    

    $('videoContainer').innerHTML = '<object width="480" height="385"><param name="movie" value="'+video+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+video+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';        
    $('videoContainer').appendChild(new Element('img',{id: 'closeVideo', src: '/themes/default/Views/Images/close.png' }));
    
    $('closeVideo').observe('click', hideVideo.bind(this));
    $('videoOverlay').observe('click', hideVideo.bind(this));

    $('videoContainer').show();
}

function hideVideo(){
    $('closeVideo').stopObserving('click', hideVideo.bind(this));
    $('videoOverlay').stopObserving('click', hideVideo.bind(this));
    
    $('videoOverlay').parentNode.removeChild( $('videoOverlay') );
    $('videoBox').parentNode.removeChild( $('videoBox') );
}

function getPageSize() {        
    var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}


