




// tear and share show hide
function tearShareShowHide(){
    glow.dom.get("#tearshare").css("display", "none"); 
    
    glow.events.addListener('#show a.expand','click',function () { 
        glow.dom.get("#tearshare").css("display", "block"); 
        glow.dom.get("#show").css("display", "none"); 
    });
    glow.events.addListener('#tearshare a.collapse','click',function () { 
        glow.dom.get("#tearshare").css("display", "none");
        glow.dom.get("#show").css("display", "block"); 
    });
    glow.events.addListener('#show a.expand','click',function (e) { e.preventDefault(); });
    glow.events.addListener('#tearshare a.collapse','click',function (e) { e.preventDefault(); });
}


// comment checking
function checkContactForm(){
    if (!document.getElementById("form-contact")) return;
    glow.events.addListener(
        '#form-contact',
        'submit',
        function (e) { 
            glow.dom.get("#form-contact li").removeClass('error');

            var rx_email =  /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;  
            var errorflag = false;
            var errors = [];
            errors.push('<p><strong>Please check your form submission</strong>:</p><ul class="error-msg">');

            if (glow.dom.get("#form-contact #name").val() == '') {    
                glow.dom.get("#form-contact #name").parent().addClass('error');
                errors.push('<li>You have to provide your name</li>');
                errorflag = true;
            }

            if (glow.dom.get("#form-contact #comments").val() == '') {    
                glow.dom.get("#form-contact #comments").parent().addClass('error');
                 errors.push('<li>There\'s no message</li>');
                 errorflag = true;

            }    

                if (glow.dom.get("#form-contact #email").val() != '') {    

                var valid_email = rx_email.test(glow.dom.get("#form-contact #email").val());
                if (!valid_email) {
                    glow.dom.get("#form-contact #email").parent().addClass('error');
                     errors.push('<li>You must provide a valid email, such as <em>name@domain.co.uk</em></li>');
                     errorflag = true;
                    } 
            }    



            errors.push('</ul>');
             var error_content = errors.join('')

            if (errorflag) {
            glow.dom.get("#form-contact #error-msg").html(error_content);    
            e.preventDefault();
            return false;
            } else {   
            return true;    
            }


        }
    );


}



// comment form checking

function checkCommentForm(){
    if (!document.getElementById("form-comment")) return;
    glow.events.addListener(
        '#form-comment',
        'submit',
        function (e) { 
            glow.dom.get("#form-comment li").removeClass('error');

            var errors = [];
            var errorflag = false;
            errors.push('<p><strong>Please check your form submission</strong>:</p><ul class="error-msg">');

            if (glow.dom.get("#form-comment #name").val() == '') {    
                glow.dom.get("#form-comment #name").parent().addClass('error');
                errors.push('<li>You have to provide your name</li>');
                errorflag = true;
            }

            if (glow.dom.get("#form-comment #comments").val() == '') {    
                glow.dom.get("#form-comment #comments").parent().addClass('error');
                 errors.push('<li>There\'s no comment</li>');
                 errorflag = true;

            }    




            errors.push('</ul>');
             var error_content = errors.join('')

            if (errorflag) {
            glow.dom.get("#form-comment #error-msg").html(error_content);    
            e.preventDefault();
            return false;
            } else {   
            return true;    
            }


        }
    );


}



function setPopUpLinks() { 



    var genpopups = glow.dom.get('a.popup');
    genpopups.each(function (i) { 
    
    	//this == myNodeList[i] 
    	
    	
    	glow.events.addListener(
		    genpopups[i],
		    'click',
		    function () { 
		    
		    	window.open(this.getAttribute('href'), 'summerpopup', 'width=640,height=480,toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar=no,status=no,resizable=yes,left=60,screenX=60,top=100,screenY=100');
		    	return false;
		    
		    }
		);
		
    	
    
    });
        
    
    
    var radiopopups = glow.dom.get('a.radiopopup');
    radiopopups.each(function (i) { 
    
    	glow.events.addListener(
		    radiopopups[i],
		    'click',
		    function () { 
		    
		    	window.open(this.getAttribute('href'), 'aod', 'width=512,height=300,toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar=no,status=no,resizable=yes,left=60,screenX=60,top=100,screenY=100');
		    	return false;
		    
		    }
		);
    
    });
    
 

}



function videoTooltips() { 
if (!document.getElementById("emp1")) return;


var thisTitle = "";

    var videothumbs = glow.dom.get('.video-nav ul li a');
    videothumbs.each(function (i) { 
    
    	glow.events.addListener(
		    videothumbs[i],
		    'mouseover',
		    function (e) { 	
				if (this.getAttribute('title') && this.getAttribute('title') != '') {
					thisTitle = this.getAttribute('title');
					this.setAttribute('title', '');
					glow.dom.get("body").append("<div id='thumbtooltip'><p>" + thisTitle + "</p></div>");	 		   	
					glow.dom.get("#thumbtooltip").css("top", (e.pageY + 5) + "px");
					glow.dom.get("#thumbtooltip").css("left", (e.pageX + 5) + "px");
					return false;		    
				}
		    }
		);
		
		
glow.events.addListener(
		    videothumbs[i],
		    'mouseout',
		    function () { 	
				this.setAttribute('title', thisTitle);
				glow.dom.get("#thumbtooltip").remove();					   
		    }
		);		
    
    });
    

}







// we want a namespaced object to run scripts

var SummerLib = {

	init : function() {

		setPopUpLinks();

	}

}