$(function() {
	
	$('#bottom-right form').validate();
	
	$("#cycle-container").fadeIn(1000);
	$("#content").fadeIn(1000);
	
	$('#cycle').after('<div id="cycle-nav">').cycle({
		fx: 'scrollLeft',
		speed: 700,
		timeout: 8000,
		pager: '#cycle-nav',
		cleartype: 0,
		cleartypeNoBg:true
	});

	$("#share-button").click(function() {
		$("#share-links").toggle();
	});
	
	$(".faq-container").click(function() {
		$(this).find(".question").toggleClass("active-faq");
		$(this).find("p").slideToggle("fast");
	});
	
	$(".styles .template-container").mouseover(function() {
		$(this).find(".styles-hover").show();
	  }).mouseout(function(){
		$(this).find(".styles-hover").hide();
	  });
	
	$(".examples .template-container").mouseover(function() {
		$(this).find(".examples-hover").show();
	  }).mouseout(function(){
		$(this).find(".examples-hover").hide();
	});
	
	$("#t-c a").click(function() {
		$("#terms").show();
	});
	
	$("#terms-close-button").click(function() {
		$("#terms").hide();
	});
	
	$("#view-details td").click(function() {
		$("#view-details").hide();
		$("#close-details").show();
		$(".hosting-details").show();
	});
	
	$("#close-details td").click(function() {
		$("#close-details").hide();
		$("#view-details").show();
		$(".hosting-details").hide();
	});
	
	Cufon.replace('h4, .larger-text, #divide span, .faq-container .question', {hover: 'true'}, { fontFamily:'Helvetica Neue LT Std', fontWeight:'400' });
	Cufon.replace('h1, h2, .larger-text strong, .larger-text span, .packages-td-100 a, .styles-hover a, .examples-hover', {hover: 'true'}, { fontFamily:'Helvetica Neue LT Std', fontWeight:'700' });
	Cufon.replace('h3', { fontFamily:'Helvetica Neue LT Std', fontWeight:'300' });
	
});

var d = document;
var safari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1) ? true : false;
var gebtn = function(parEl,child) { return parEl.getElementsByTagName(child); };
onload = function() {

    var body = gebtn(d,'body')[0];
    body.className = body.className && body.className != '' ? body.className + ' has-js' : 'has-js';

    if (!d.getElementById || !d.createTextNode) return;
    var ls = gebtn(d,'label');
    for (var i = 0; i < ls.length; i++) {
        var l = ls[i];
        if (l.className.indexOf('label_') == -1) continue;
        var inp = gebtn(l,'input')[0];
        if (l.className == 'label_check') {
            l.className = (safari && inp.checked == true || inp.checked) ? 'label_check c_on' : 'label_check c_off';
            l.onclick = check_it;
        };
        if (l.className == 'label_radio') {
            l.className = (safari && inp.checked == true || inp.checked) ? 'label_radio r_on' : 'label_radio r_off';
            l.onclick = turn_radio;
        };
    };
};
var check_it = function() {
    var inp = gebtn(this,'input')[0];
    if (this.className == 'label_check c_off' || (!safari && inp.checked)) {
        this.className = 'label_check c_on';
        if (safari) inp.click();
    } else {
        this.className = 'label_check c_off';
        if (safari) inp.click();
    };
};
var turn_radio = function() {
    var inp = gebtn(this,'input')[0];
    if (this.className == 'label_radio r_off' || inp.checked) {
        var ls = gebtn(this.parentNode,'label');
        for (var i = 0; i < ls.length; i++) {
            var l = ls[i];
            if (l.className.indexOf('label_radio') == -1)  continue;
            l.className = 'label_radio r_off';
        };
        this.className = 'label_radio r_on';
        if (safari) inp.click();
    } else {
        this.className = 'label_radio r_off';
        if (safari) inp.click();
    };
};
