$(document).ready(function(){
	if (!$("body").get(0)) { return }

	if ($("body").hasClass("fixed")) { $("body").removeClass("fixed") }
	else { $("body").get(0).className = ($.cookie("style") || "gold").replace( $("#content").hasClass("l310") ? /viola/ : /brown/ , "gold"); }

	$("#buyit #wheretobuy").addClass("active").removeAttr("href").click(function(){ $("#shoplist").toggle(); return false; });
	$("#shoplist ins.close").click(function(){ $("#shoplist").hide() });
	$("#shoplist").click(function(){ return false; });
	$("#shoplist #shops a").click(function(){ window.location.href="http://funclub.samsung.ua/shops/" });
	$("body").click(function(){ $("#shoplist").hide() });

	if ($("#model").get(0)) {
		$("#model ul.selector u").css("visibility","visible").click(function(){ $("body").get(0).className = this.className });
		$("#model #views small").addClass("active");
		$("#model #views small img").click(function(){ $("#views").get(0).className = this.className });
		$("#model a[href^='/']").click(function(){ $.cookie("style",$("body").get(0).className,{path:'/'}) });
		$("#model #techinfo").click(function(){ $("#tech").toggle(); });
		$.preloadCssImages();
	}

	$("#test input").click(function(){
		$("input[name='" + this["name"] + "']").parent().removeClass("checked");
		this.parentNode.className = "checked";
		this.parentNode.parentNode.className = "checked";
		if ($("input[checked]").length < 10) return;
		var max = 0; var cnt = 0; var ans = 0; var i = 4;
		while (i--) {
			cnt = $("input[checked][value='" + i + "']").length;
			if (cnt > max) { max = cnt; ans = i; }
		}
		$("p.rep").hide();
		$("#ans" + ans).show();
	});

	$("#chat #rules").click(function(){ window.open(this.href, "popup", "width=660,height=600,scrollbars=1,resizable=1,"); return false; });
	$("#chat #sendform #sendbutton").click(function(){
		$.post("/send/",
				{ name: $("#Qname").val(), email: $("#Qemail").val(), desc: $("#Qdesc").val() },
				function(){ $("#chat #sendform #thnx").show() }
		);
		return false;
	});

})

// Cookie plugin
//
// Copyright (c) 2006 Klaus Hartl, klaus.hartl@stilbuero.de, http://stilbuero.de
// Dual licensed under the MIT and GPL licenses

$.cookie = function(name, value, options) {
	if (typeof value != 'undefined') {
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString();
		}
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else {
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};

// preloadCssImages Plugin
//
// origin by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
// Dual licensed under the MIT and GPL licenses

$.preloadCssImages = function(){
	var cssPile = '';
	($.browser.msie)
		? $.each($.makeArray(document.styleSheets),function(){cssPile+=this.cssText})
		: $.each(document.styleSheets,function(){$.each(this.cssRules,function(){cssPile+=this.cssText})});
	var ptr = document.preloadedCssImages = [];
	re = /url\"?\(([^\)]*)\"?\)|src='([^']*)'/ig;
	while ( match = re.exec(cssPile) ) {
		ptr[ptr.push(new Image())-1].src = match[1] || match[2];
	}
}

