// --------------------------------------------------------------------------
// Blocks scroller by IonDen. 08.09.2010

(function($){
    $.fn.set_ds = function(options) {
		var defaults = {
			step : 100,
			num : 2
		};
		var options = $.extend(defaults, options);
		var $ds = $("#" + $(this).attr("id"));
		var side_num = $ds.find("td.ds_side").length;
		var current = 0;
		var $arr = $ds.find("a.arr");
		var $base = $ds.find("div.b_head");
		var $bck = $ds.find("a.bck");
		var $fwd = $ds.find("a.fwd");
		var $scr = $ds.find("div.ds_scroll");
		
		$bck.click(function(e) {
			e.preventDefault();
			ds_go(-1);
		});
		
		$fwd.click(function(e) {
			e.preventDefault();
			ds_go(1);
		});
		
		$base.bind("mousedown", function() {
			return false;
		});
		
		function ds_go(to) {
			current = current + to;
			if(current < 0) {current = 0};
			if(current > side_num - options.num) {current = side_num - options.num};
			$scr.animate({left:options.step * -current},200,set_arrs);
		}
		
		function set_arrs() {
			if(current == 0) {
				$bck.hide();
				$fwd.show();
			} else if(current == side_num - options.num) {
				$bck.show();
				$fwd.hide();
			} else {
				$bck.show();
				$fwd.show();
			}
		}
		set_arrs();
	}
})(jQuery);

// --------------------------------------------------------------------------
// Main menu by IonDen. 10.09.2010

$(document).ready(function(){
	var m_current = 0;
	var $mma = $("#mmenu a");
	var $submenu = $("#top dd");
	var swt = 0;
	$mma.each(function(index){
		if($(this).hasClass("on")) {
			$("#submenu_" + index).slideDown(200);
			swt = 1;
		}
		$(this).mouseenter(function(){
			if (swt == 0) {
				$mma.removeClass("on");
				$(this).addClass("on");
				$submenu.slideUp(200);
				$("#submenu_" + index).slideDown(200);
			}
		});
	});
	
	// --------------------------------------------------------------------------
	// Tabs widget by IonDen. 09.09.2010

	if($("div.tabs").length != 0) {
		var $tabs = $(".tabs");
		var tabs_num = $tabs.find("a").length;
		var tabs_hash = document.location.hash;
		if(tabs_hash === "") {tabs_hash = "#tab0"};
		var current_tab = parseInt(tabs_hash.slice(4));
		$tabs.find("a[href='" + tabs_hash + "']").addClass("on");
	
		$tabs.find("a").click(function() {
			$tabs.find("a").removeClass("on");
			$(this).addClass("on");
			tabs_hash = $(this).attr("href");
			current_tab = parseInt(tabs_hash.slice(4));
			set_tabs();
		});
	
		function set_tabs() {
			$("div.tab").hide();
			$("#tab_cont_" + current_tab).show();
		};
		set_tabs();
	}
});


/* -------------------------------------------------------------------------------------------------------------------------
 * nice image slider
 * by IonDen
 * 07.07.2010
 */

(function($){
    $.fn.nice_slider = function(options) {
        var defaults = {
            delay: 5
        };
        var options = $.extend(defaults, options);
		
		var nice_id = "#" + $(this).attr("id");
		var nice_num = $(nice_id + " > a.nice_pic").length;
		var current_num = 0;
		var old_num = 0;
		var first_start = true;
		var timer = 0;
		
		if (nice_num == 1) {
			
			slide();
			$("#vp_arrs").css('display', 'none');
			
		} else if(nice_num > 1) {
			
			var exec_timer = setInterval(slide,1000);
			 
			$("#view_pic").bind("mouseenter",function() {
				$("#vp_arrs").fadeIn(300);
			});
			$("#view_pic").bind("mouseleave",function() {
				$("#vp_arrs").fadeOut(300);
			});
			
		} else {
			$("a.nice_pic:eq(0)").css("top",0).fadeIn(1000);
			set_link();
		}
		
		function slide() {
			if(timer < options.delay) {
				timer++;
				if(timer === 1) {
					clear_once();
				}
			} else {
				timer = 0;
				if(current_num < nice_num - 1) {
					old_num = current_num;
					current_num++;
					
					set_link();
					$("a.nice_pic:eq("+old_num+")").fadeOut(1000);
					$("a.nice_pic:eq("+current_num+")").css("top",0).fadeIn(1000);
				} else {
					old_num = current_num;
					current_num = 0;

					set_link();
					$("a.nice_pic:eq("+old_num+")").fadeOut(1000);
					$("a.nice_pic:eq("+current_num+")").css("top",0).fadeIn(1000);
				}
			}
		}
		
		function slide_act(num) {
			timer = 0;
			old_num = current_num;
			current_num = current_num + num;
			if(current_num < 0) {current_num = nice_num - 1};
			if(current_num >= nice_num) {current_num = 0};
			
			set_link();
			$("a.nice_pic:eq("+old_num+")").fadeOut(1000);
			$("a.nice_pic:eq("+current_num+")").css("top",0).fadeIn(1000);
		}
		
		function clear_once() {
			if(first_start === true) {
				$(nice_id).css("background","#B3B3B3");
				first_start = false;
				$("a.nice_pic:eq(0)").css("top",0).fadeIn(500);
				set_link();
			}
		}
		
		function set_link() {
			var url = $("a.nice_pic:eq("+current_num+")").attr("href");
			$("#mask_link").attr("href",url);
		}
		
		$("#nice_back").click(function(e) {
			e.preventDefault();
			slide_act(-1)
		});
		$("#nice_fwd").click(function(e) {
			e.preventDefault();
			slide_act(1)
		});
	}
})(jQuery);
function wordwrap (str, int_width, str_break, cut) {
    var m = ((arguments.length >= 2) ? arguments[1] : 75   );
    var b = ((arguments.length >= 3) ? arguments[2] : "\n" );    var c = ((arguments.length >= 4) ? arguments[3] : false);
 
    var i, j, l, s, r;
 
    str += ''; 
    if (m < 1) {
        return str;
    }
     for (i = -1, l = (r = str.split(/\r\n|\n|\r/)).length; ++i < l; r[i] += s) {
        for (s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
            j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
        }
    }    
    return r.join("\n");
}

