$(document).ready(function() {

$("input#search-field").labelify({labelledClass: "placeholder"});

$('.button').click(function() { setTimeout(function() {$(this).attr("disabled","disabled");}, 1000);});

$('.n1').addClass('invisible');
$('.n2').addClass('invisible');
$('.n3').addClass('invisible');
$('.n4').addClass('invisible');
$('.n5').addClass('invisible');
$('.n6').addClass('invisible');
$('.n7').addClass('invisible');
$('.n8').addClass('invisible');
$('.n9').addClass('invisible');
$('.n10').addClass('invisible');
$('.n11').addClass('invisible');
$('.n12').addClass('invisible');
$('.n13').addClass('invisible');
$('.n14').addClass('invisible');
$('.n15').addClass('invisible');
$('.n16').addClass('invisible');
$('.n17').addClass('invisible');
$('.n18').addClass('invisible');
$('.n19').addClass('invisible');
$('.n20').addClass('invisible');

$('.subblock1 span').click(function() {
$('.subblock1').addClass('active');
$('.subblock1 span').removeClass('pseudo');
$('.subshow1').removeClass('invisible');
$('.subblock2').removeClass('active');
$('.subblock2 span').addClass('pseudo');
$('.subshow2').addClass('invisible');
$('.subblock3').removeClass("active");
$('.subblock3 span').addClass('pseudo');
$('.subshow3').addClass('invisible');
$('.subblock4').removeClass("active");
$('.subblock4 span').addClass('pseudo');
$('.subshow4').addClass('invisible');
});

$('.subblock2 span').click(function() {
$('.subblock2').addClass('active');
$('.subblock2 span').removeClass('pseudo');
$('.subshow2').removeClass('invisible');
$('.subblock1').removeClass('active');
$('.subblock1 span').addClass('pseudo');
$('.subshow1').addClass('invisible');
$('.subblock3').removeClass('active');
$('.subblock3 span').addClass('pseudo');
$('.subshow3').addClass('invisible');
$('.subblock4').removeClass("active");
$('.subblock4 span').addClass('pseudo');
$('.subshow4').addClass('invisible');
});

$('.subblock3 span').click(function() {
$('.subblock3').addClass('active');
$('.subblock3 span').removeClass('pseudo');
$('.subshow3').removeClass('invisible');
$('.subblock1').removeClass('active');
$('.subblock1 span').addClass('pseudo');
$('.subshow1').addClass('invisible');
$('.subblock2').removeClass('active');
$('.subblock2 span').addClass('pseudo');
$('.subshow2').addClass('invisible');
$('.subblock4').removeClass("active");
$('.subblock4 span').addClass('pseudo');
$('.subshow4').addClass('invisible');
});

$('.subblock4 span').click(function() {
$('.subblock4').addClass('active');
$('.subblock4 span').removeClass('pseudo');
$('.subshow4').removeClass('invisible');
$('.subblock1').removeClass('active');
$('.subblock1 span').addClass('pseudo');
$('.subshow1').addClass('invisible');
$('.subblock2').removeClass('active');
$('.subblock2 span').addClass('pseudo');
$('.subshow2').addClass('invisible');
$('.subblock3').removeClass("active");
$('.subblock3 span').addClass('pseudo');
$('.subshow3').addClass('invisible');
});

$('.n1open').click(function() {
$('.n1').toggle();
});

$('.n2open').click(function() {
$('.n2').toggle();
});

$('.n3open').click(function() {
$('.n3').toggle();
});

$('.n4open').click(function() {
$('.n4').toggle();
});

$('.n5open').click(function() {
$('.n5').toggle();
});

$('.n6open').click(function() {
$('.n6').toggle();
});

$('.n7open').click(function() {
$('.n7').toggle();
});

$('.n8open').click(function() {
$('.n8').toggle();
});

$('.n9open').click(function() {
$('.n9').toggle();
});

$('.n10open').click(function() {
$('.n10').toggle();
});

$('.n11open').click(function() {
$('.n11').toggle();
});

$('.n12open').click(function() {
$('.n12').toggle();
});

$('.n13open').click(function() {
$('.n13').toggle();
});

$('.n14open').click(function() {
$('.n14').toggle();
});

$('.n15open').click(function() {
$('.n15').toggle();
});

$('.n16open').click(function() {
$('.n16').toggle();
});

$('.n17open').click(function() {
$('.n17').toggle();
});

$('.n18open').click(function() {
$('.n18').toggle();
});

$('.n19open').click(function() {
$('.n19').toggle();
});

$('.n20open').click(function() {
$('.n20').toggle();
});


$('.opener').click(function() {
$(this).next().toggle();
});

$('.scheme-open .pseudo').click(function() {
		$('.scheme-big').slideToggle('slow');
		return false;
});

	
$('.scheme-close').click(function() {
		$('.scheme-big').slideToggle('slow');
		return false;
});

$('.login-open').click(function() {
		$(".login_form").animate({top:'-4px', right:'-12px'}, 500);

		return false;
});
	
$('.login-close').click(function() {
		$(".login_form").animate({top:'-300px', right:'-300px'}, 500);
		return false;
});

});

function ShowImgWindow(title, src, width, height) {

	obj = window.open("", "", "scrollbars=0,dialog=0,minimizable=1,modal=1,width="+width+",height="+height+",resizable=0, left=100,top=100");
	obj.document.write("<html>");
	obj.document.write("<head>");
	obj.document.write("<title>"+title+"</title>");
	obj.document.write("</head>");
	obj.document.write("<body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>");
	obj.document.write("<img src=\""+src+"\" />");
	obj.document.write("</body>");
	obj.document.write("</html>");
}

var win = null;
function ShowFormWindow(mypage, myname, w, h, scroll, pos) {
    if (pos == "random") {
        LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100;
        TopPosition = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100;
    }
    if (pos == "center") {
        LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
        TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;
    } else if ((pos != "center" && pos != "random") || pos == null) {
        LeftPosition = 0;
        TopPosition = 20
    }
    settings = 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
    win = window.open(mypage, myname, settings);
}

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();


addEvent(window,'unload',EventCache.flush);

function CssClassesHandler(object) { this.object = object }

CssClassesHandler.prototype = {
    object      : null,
    
    all         : function() {
                    return this.object.className.split(/\s+/)
                },

    exists      : function(className) {
                    var classes = this.all()
                    for(var i = 0; i < classes.length; i++)
                        if(classes[i] == className) return true
                    return false
                },

    add         : function(className) {
                    var classes = this.all()
                    for(var i = 0; i < classes.length; i++)
                        if(classes[i] == className) return
                    this.object.className = this.object.className + " " + className
                },

    remove      : function(className) {
                    var classes = this.all()
                    var cn = ""
                    for(var i = 0; i < classes.length; i++) {
                        var isMatch = (typeof className.test == "function")
                            ? className.test(classes[i])
                            : (classes[i] == className)
                        if(!isMatch) cn = cn + " " + classes[i]
                    }
                    this.object.className = cn.substr(1)
                },

    set         : function(className, state) {
                    if(state)
                        this.add(className)
                    else
                        this.remove(className)
                },

    flip        : function(className) {
                    if(this.exists(className))
                        this.remove(className)
                    else
                        this.add(className)
                }
}

function CssClasses(object) {
    return new CssClassesHandler(object)
}

function checkValue(obj) {
    if($(obj).attr('id') == 'email') {
		if($('#email').val().match(/[0-9a-z_]+@[0-9a-z_^.]+\.[a-z]{2,3}/i)) {
			$('#lemail').removeAttr('class');
		}
		else {
			$('#lemail').attr('class','red');
		}
	}
	if($(obj).attr('class') == 'phonepart') {
		if($('#phone_part1').val().match(/^([+]?)([0-9])+$/) && $('#phone_part2').val().match(/^([0-9])+$/) && $('#phone_part3').val().match(/^([0-9])+$/) && $('#phone_part4').val().match(/^([0-9])*$/)) {
			$('#lphone').removeAttr('class');
		}
		else {
			$('#lphone').attr('class','red');
		}
	}
	if($(obj).attr('type') == 'radio') {
        if($(obj).parent().children('input[checked]').length > 0) {
            $(obj).parent().prev().children('label').removeAttr('class'); 
            $(obj).parent().prev().prev().children('label').removeAttr('class');
        }
        else {
            $(obj).parent().prev().children('label').attr('class','red');
        }
    }
    if($(obj).attr('type') == 'checkbox') {
        if($(obj).parent().children('input[checked]').length > 0)
            $(obj).parent().prev().children('label').removeAttr('class'); 
        else
            $(obj).parent().prev().children('label').attr('class','red');
    }

    else {
        if($(obj).val())
            $(obj).parent().prev().children('label').removeAttr('class');
        else
            $(obj).parent().prev().children('label').attr('class','red');
    }
    
    return true;
}
