//Fader settings
var fadeInSpeed = 800;
var fadeOutSpeed = 1500;
var slideDuration = 4000;
var slideClass = '.fade-slide';

$(function(){

    $("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
    
    loadShadowbox();
    $(slideClass).hide();
    fader();
});

function uncheck(elemID) {
	$('#' + elemID).attr('checked', false);
}

function createSections() {
	var num = $('#sections').val();
	var html = "";
	for(var i=1; i<=num; i++) {
		html += '<div id="form-row">';
		html += '<div id="sectionContainer">';
		html += 'Section '+ i +' Size: <input type="text" name="section'+ i +'length" size="4" /> mm long, <input type="text" name="section'+ i +'thickness" size="4" /> mm thick, <input type="text" name="section'+ i +'width" size="4" /> mm wide - No cut <input type="checkbox" id="s'+ i +'nocut" name="section'+ i +'cuts[]" value="none" checked onclick="uncheck(\'s'+ i +'cutsink\'); uncheck(\'s'+ i +'cuthob\');" /> Sink <input type="checkbox" name="section'+ i +'cuts[]" value="sink" onClick="uncheck(\'s'+ i +'nocut\')" id="s'+ i +'cutsink" /> Hob <input type="checkbox" name="section'+ i +'cuts[]" value="hob" onClick="uncheck(\'s'+ i +'nocut\')" id="s'+ i +'cuthob" /></div></div>'	
	}
	$('#sectionContainer').html(html);
}

function isGoodBrowser() {
	var rv = 7;
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
	var ua = navigator.userAgent;
	var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if (re.exec(ua) != null)
	rv = parseFloat( RegExp.$1 );
	}
	
	if(rv > 6) {	
		return true;
	} else {
		return false;
	}	
}

function loadShadowbox() {
	if(isGoodBrowser()) {
		Shadowbox.init();
	}
}


function popupIE6(image) {
	if(!isGoodBrowser()) {
		window.open (image, "imageWindow","menubar=1,resizable=1,width=350,height=250");
	}
}


function fader()
{
	var current = $(slideClass + ':first');
	current.addClass('fader-active').fadeIn(fadeInSpeed, function() {
		var tmpfn = function() { fade(current); };
		setTimeout(tmpfn, slideDuration);
	});
}

function fade(current)
{
	current.fadeOut(fadeOutSpeed, function() {
		current.removeClass('fader-active');
		var next = current.next();
		if (!next.size()) {
			fader();
		} else {
			var tmpfn = function() { fade(next); }
			next.addClass('fader-active').fadeIn(fadeInSpeed, function() {
				setTimeout(tmpfn, slideDuration);
			});
		}
	});
}

