$(window).load(function() {
//	$("#main").css({opacity: 1, filter: 'alpha(opacity=100)'});
})
$(document).ready(function() {
	posVideo();
	showContent();
	$(window).resize(function() {
		posVideo();
		showContent();
	})
	
	//visible content
var id;
	$(".news").parent().css("display", "none");
	$(".all").parent().css("display", "block");
	$("#s4").append($("#adsArchive a.home").clone());
	$("#visibility_types a").each(function(){
		$(this).click(function(){
			id=$(this).attr('id');
			if (!$(this).attr('class')) {
				$("#visibility_types a").removeClass('active').html('&#8201;&#8201;&#8201;&#8201;');
				$(this).attr('class', 'active');
				$(this).html('X');
				$('.news, #all').css({display: 'none'});
				$('#s4 a.ads').remove();
				$("."+$(this).attr('id')).css({display:'block'});
				$(".bucket").each(function(){
					if (!$(this).children("."+id).length && $(this).children(".news").length)
						$(this).css({ display: 'none'});
					else 
						$(this).css({ display: 'block'});
				});
				$("#s4").append($("#adsArchive a."+$(this).attr('id')).clone());
			} else {
				$(this).removeClass('active');
				$(this).html('&#8201;&#8201;&#8201;&#8201;');
				$('.news, #all').css({display: 'none'});
				$('#s4 a.ads').remove();
				$("."+$(this).attr('id')).css({display:'none'});
				$("#s4").append($("#adsArchive a."+$(this).attr('id')).clone());
				if (!$("#visibility_types a.active").length) {
					$('.news').css({display: 'none'});
					$('.all').css({display: 'block'});
					$(".news").parent().css("display", "none");
					$(".all").parent().css("display", "block");
					$('#s4 a.ads').remove();
					$("#s4").append($("#adsArchive a.home").clone());
				}
			}
			$("#slidernav").remove();
			slider();
			return false;
		})
	})
})

function valAttr(id){$('#'+id).attr('value',$('#'+id).attr('value')+' *')}

function loadContent(id) {
        $("#fullContent").prepend('<div id="removable">'+$("#"+id).html()+'</div>');
	showContent();
	$("#bg").css({display: 'block'});
	$("#layer").css({display: 'block'});
}

function showContent() {
	$("#bg").css({width: $(window).width(), height: $(window).height()});
	$("#layer").css({width: $(window).width()-100, marginLeft: 50, height: $(window).height()-100, top: 50});
	$("#layer table:first").css({height: $(window).height()-100});
	$("#removable").css({height: $(window).height()-200});
}

function hideContent() {
	$("#layer").css({display: 'none'});
	$("#nform").css({display: 'none'});
	$("#bg").css({display: 'none'});
	$("#removable").remove();
}

function checkMail(email) {   
	if (email.indexOf('@')>0 && email.indexOf('.')>0) {
		return true;
	} else {
		return false;
	}
}

function loadForm(email, url) {
	$.ajax ({
		url: url,
		dataType: 'html',
		method: 'post',
		success: function(data) {
			$("#nform").html(data);
			$("input[name=data[email_newslettersForm]]").attr('value', email);
			$("#bg").css({width: $(window).width(), height: $(window).height()});
			$("#nform").css({marginLeft: ($(window).width()-$("#nform").width())/2, top: ($(window).height()-$("#nform").height())/2});
			$("#bg, #nform").css({display: 'block'});
			$("#nform form:first").submit(function() {
				$.ajax ({
					url: $(this).attr("action"),
					dataType: 'html',
					method: 'post',
					data: $(this).serializeArray(),
					success: function(data) {
						$("#nform").html(data);
						$("#bg").css({width: $(window).width(), height: $(window).height()});
						$("#nform").css({marginLeft: ($(window).width()-$("#nform").width())/2, top: ($(window).height()-$("#nform").height())/2});
						$("#bg, #nform").css({display: 'block'});
					}
				})
				return false;
			})
		}
	})
}

function showVideo(object) {            
	$("#videoContent td:first").html(object);
	posVideo();
	$("#bg1, #videoContent").css({display: 'block'});
}

function posVideo() {
	$("#bg1").css({width: $(window).width(), height: $(window).height()});
	$("#videoContent").css({marginLeft: ($(window).width()-$("#videoContent").width())/2, top: ($(window).height()-$("#videoContent").height())/2});
}

function hideVideo() {
	$("#videoContent").css({display: 'none'});
	$("#videoContent td:first").html("");
	$("#bg1").css({display: 'none'});
}

function setColor(color) {
	if(color != '') { 
		$(".lt, .lb, .rt, .rb").css({backgroundImage: 'url(/templates/i/border'+color+'.png)'});
		$(".titleText").css('color', '#'+color);
		$(".l, .t, .r, .b").css('border-color', '#'+color);
//		$("#bg").css('background-color', '#'+color);
	}
}

function slider() {
	$.fn.cycle.defaults.timeout = 6000;
	$(function() {
		$('table pre code').not('#skip,#skip2').each(function() {
			eval($(this).text());
		});
        	$('#s4').before('<div id="slidernav" class="slidernav">').cycle({
			fx:     'scrollLeft',
			speed:  'slow',
			timeout: 7000,
			pager:  '#slidernav'
		});
	});
}

function onBefore() {
	$('#output').html("Scrolling image:<br>" + this.src);
}

function onAfter() {
	$('#output').html("Scroll complete for:<br>" + this.src).append('<h3>' + this.alt + '</h3>');
}



