$('.banner').cycle({
fx: 'fade',
speed:    2500, 

});

// JavaScript Document
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

//DROPDOWN NAV
function drop_open(){
	drop_canceltimer();
	ddmenuitem = $('.dropdown').slideDown(400);
}

function drop_close(){
	if(ddmenuitem){
		$('.dropdown').slideUp(400);
	}
}

function drop_timer(){
	closetimer = window.setTimeout(drop_close, timeout);
}

function drop_canceltimer(){
	if(closetimer){
		window.clearTimeout(closetimer);
      	closetimer = null;
	}
}
//end nav




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;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		


function closetel(){
$('#jquery-overlay, .tell').fadeOut(600,function(){$('#jquery-overlay, .tell').remove();});	
}


//box
function showtell(){
	$("body").append('<div class="tell"><h2>Tell a Friend</h2><div class="emailerror">Please enter both fields.</div><form id="tellform" action="tellsubmit.php" method="post"><label for="tellname">Your name:*</label><input type="text" name="name" id="tellname" class="input1" /><br /><label for="tellemail">Friend\'s Email:*</label><input type="text" id="tellemail" name="email" class="input1" /><br /><input type="submit" class="submitbut" value="Submit" /></form><div class="aftermath"></div></div><div id="jquery-overlay"></div>');
	var arrPageSizes = getPageSize();
	$("#jquery-overlay").css({
		opacity: 0.8,
		width: arrPageSizes[0],
		height:	arrPageSizes[1]
	}).fadeIn(600);
	
	$(".tell").css({
		left:	(arrPageSizes[0]/2)-135
	}).fadeIn(600);
	

	$('#jquery-overlay').click(closetel);
	
	
	$(window).resize(function() {
		// Get page sizes
		var arrPageSizes = getPageSize();
		// Style overlay and show it
		$('#jquery-overlay').css({
			width:		arrPageSizes[0],
			height:		arrPageSizes[1]
		});
		$(".tell").css({
			left:	(arrPageSizes[0]/2)-135
		});
	});
	
	
	
	$("#tellform").submit(function() {
    	$('.emailerror').hide();
		
		//VALIDATION
		var email = $("input[name='email']").val();
        if (email == "") {
        $("div.emailerror").slideToggle("normal");
        $("#tellemail").focus();
        return false;
        }
		
		
		var name = $("input[name='name']").val();
        if (name == "" || name == "yourname") {
        $("div.emailerror").slideToggle("normal");
        $("#tellname").focus();
        return false;
        }
		
		//var catcha = $("input[name='catch']").val();
		
		$('#tellform').slideUp(300);
		$('.emailerror').css({background:'#aac301'}).html('Sending your message...').slideDown(300);
      	
		
		//SUBMISSION
		var dataString = 'name=' + name + '&email=' + email + '&subby=ajax';
  		//alert (dataString);return false;
  		$.ajax({
    		type: "POST",
    		url: "tellsubmit.php",
    		data: dataString,
    		error: function(){
				$('.emailerror').css({background:'#ff0000'}).html('Message Failed.'); 
				$('.aftermath').hide().html('<a href="javascript:closetel()" class="submitbut" style="margin-left:0px;">Close</a>').slideDown(300);
			},
			success: function() {
      			$('.emailerror').html('Message sent successfully! Thanks.'); 
				$('.aftermath').hide().html('<a href="javascript:closetel()" class="submitbut" style="margin-left:0px;">Close</a>').slideDown(300);

    		}
  		});
  		return false;
		
		
   }); //form submit close 
	
	

};


function favoris(){window.external.AddFavorite(location.href,"MCC Small Electricals");}

$(function(){
	$('.servicesbut, .dropdown').hover(drop_open, drop_timer);
	//$('.servicesbut, .dropdown').bind('mouseout',);
	
	$('.tellafriend').bind('click',showtell);
	
	
	
	
	if ( navigator.appName == 'Microsoft Internet Explorer' ) {
	$('.level0').prepend('<a href="javascript:void(favoris());" class="bookmark">Bookmark us</a>');
	}
	
});



