$().ready(function () {
	$('body').disableTextSelect();
	$('body').disableCntrlPlus(65);

	$("ul.dropdown > li > a.onn").each(function (i, el) {
		var s = $(el).html();
		$(el).html("<i><b>" + s + "</b></i>");
	}); //.html("<i><b>" + $("ul.dropdown li a.onn").html() + "</b></i>");
	$(".nav_sub a").each(function (i, el) {
		var s = $(el).html();
		$(el).html("<i><b>" + s + "</b></i>");
	});

	$(".hp-tabs-cnt .img_border").hover(
		function () {
			clearTimeout(__timer);
		},
		function () {
			__timer = setTimeout("galimgauto()", __timeout);
		}
	);

	//ie6 fixes
	if (isIE6) {
		$("ul.dropdown > ul, ul.dropdown li ul li").addClass('pngfix');
		$("ul.dropdown ul").css({
			visibility: 'hidden'
		});
		$("ul.dropdown > li > a:link, ul.dropdown > li > a:visited").css({
			padding: '0 7px',
			display: 'block'
		});
		$(".cms_heb ul.dropdown > li > a:link, .cms_heb ul.dropdown > li > a:visited").css({
			padding: '0 12px'
		});
		$(".cms_rus ul.dropdown > li > a:link, .cms_rus ul.dropdown > li > a:visited").css({
			padding: '0 6px',
			fontSize: '12px',
			lineHeight: '32px'
		});
		$("ul.dropdown > li > a.onn:link, ul.dropdown > li > a.onn:visited").css({
			background: 'url(/app_themes/default/images/menu_c.gif) repeat-x',
			padding: '0 !important'
		});
		$("ul.dropdown li ul li:hover > a:link,ul.dropdown li ul li:hover > a:visited").css({
			textDecoration: 'none',
			color: '#595959'
		});
	}

	$('.lt_rslt').mouseenter(function () {
		$(this).addClass('lt_rslt_onn');
	}).mouseleave(function () {
		$(this).removeClass('lt_rslt_onn');
	});

	$("span.a").click(function () {
		if ($(this).attr("href"))
			wourl($(this).attr("href"));
	});
});


/*(function ($) {
	$.fn.customFadeIn = function (speed, callback) {
		$(this).fadeIn(speed, function () {
			if (jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if (callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function (speed, callback) {
		$(this).fadeOut(speed, function () {
			if (jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if (callback != undefined)
				callback();
		});
	};
})(jQuery);

*/
(function ($) {
	$.fn.customFadeIn = function (speed, callback) {
		$(this).fadeIn(speed, function () {
			if (!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if (callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function (speed, callback) {
		$(this).fadeOut(speed, function () {
			if (!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if (callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = function (speed, to, callback) {
		return this.animate({ opacity: to }, speed, function () {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);



var __last_tab = null;
function initTabs(tbl) {
	__last_tab = $('.hp-tabs-cnt').find('.tab1');
	var tab1 =
	tbl.children().hover(
		function () {
			if (!$(this).hasClass("ok"))
				$(this).addClass("hover");
		},
		function () {
			if (!$(this).hasClass("ok"))
				$(this).removeClass("hover");
		}
	).click(
		function () {
			if (!$(this).hasClass("ok")) {
				tbl.children().removeClass("on").removeClass("hover").removeClass("ok");
				$(this).addClass("on").addClass("ok");
				var tab = $(this);
				__last_tab.customFadeOut("fast", function () {
					if (tab.hasClass("tb1")) {
						__last_tab = $('.hp-tabs-cnt').parent().find('.tab1');
						initImgs($('.tab1 .tab_imgs'));
					}
					if (tab.hasClass("tb2")) {
						__last_tab = $('.hp-tabs-cnt').parent().find('.tab2');
						initImgs($('.tab2 .tab_imgs'));
					}
					if (tab.hasClass("tb3")) {
						__last_tab = $('.hp-tabs-cnt').parent().find('.tab3');
						initImgs($('.tab3 .tab_imgs'));
					}
					__last_tab.customFadeIn(400);
				});
			}

			if (isIE6) {
				//$(".hp-tabs-hdr div.tb1").css('background', 'url(/app_themes/default/images/index_gallery_tab1_on.gif) no-repeat');
				tbl.children().removeClass("on").removeClass("hover").removeClass("ok");
				$(".hp-tabs-hdr div.tb1").hover(
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab1_over.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab1_on.gif) no-repeat'); },
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab1.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab1_on.gif) no-repeat'); }
				);
				$(".hp-tabs-hdr div.tb2").hover(
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab2_over.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab2_on.gif) no-repeat'); },
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab2.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab2_on.gif) no-repeat'); }
				);
				$(".hp-tabs-hdr div.tb3").hover(
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab3_over.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab3_on.gif) no-repeat'); },
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab3.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab3_on.gif) no-repeat'); }
				);
				//$(".hp-tabs-hdr div.tb2.hover").css('background', 'url(images/index_gallery_tab2_over.gif) no-repeat');
				//$(".hp-tabs-hdr div.tb3.hover").css('background', 'url(images/index_gallery_tab3_over.gif) no-repeat');
			}
		}
	);

		tbl.children().each(function (i, el) {
			if (isIE6) {
				//$(".hp-tabs-hdr div.tb1").css('background', 'url(/app_themes/default/images/index_gallery_tab1_on.gif) no-repeat');
				$(el).children().removeClass("on").removeClass("hover").removeClass("ok");
				$(".hp-tabs-hdr div.tb1").hover(
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab1_over.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab1_on.gif) no-repeat'); },
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab1.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab1_on.gif) no-repeat'); }
				);
				$(".hp-tabs-hdr div.tb2").hover(
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab2_over.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab2_on.gif) no-repeat'); },
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab2.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab2_on.gif) no-repeat'); }
				);
				$(".hp-tabs-hdr div.tb3").hover(
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab3_over.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab3_on.gif) no-repeat'); },
					function () { if (!$(this).hasClass("ok")) $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab3.gif) no-repeat'); else $(this).css('background', 'url(/app_themes/default/images/index_gallery_tab3_on.gif) no-repeat'); }
				);
				//$(".hp-tabs-hdr div.tb2.hover").css('background', 'url(images/index_gallery_tab2_over.gif) no-repeat');
				//$(".hp-tabs-hdr div.tb3.hover").css('background', 'url(images/index_gallery_tab3_over.gif) no-repeat');
			}
		});
	}




/******************************************************************************************/
function carousel_initCallback(carousel) {
	$('.last_prjcts .albm_l').bind('click', function () {
		if (__lang == 'he') carousel.next();
		else carousel.prev();
		return false;
	});
	$('.last_prjcts .albm_r').bind('click', function () {
		if (__lang == 'he') carousel.prev();
		else carousel.next();
		return false;
	});
	$(".last_prjcts .albm_in").bind('mousewheel', function (event, delta) {
		if (delta < 0) carousel.prev();
		else carousel.next();
		return false;
	});
}
function carousel2_initCallback(carousel) {
	$('.our_clients .albm_l').bind('click', function () {
		if (__lang == 'he') carousel.next();
		else carousel.prev();
		return false;
	});
	$('.our_clients .albm_r').bind('click', function () {
		if (__lang == 'he') carousel.prev();
		else carousel.next();
		return false;
	});
	$(".our_clients .albm_in").bind('mousewheel', function (event, delta) {
		if (delta < 0) carousel.prev();
		else carousel.next();
		return false;
	});
}

/****************************************************************************/
var __index = 1;
var __scroller = null;
var __gallery = null;
var __last_img = null;
var __timer = 0;
var __timeout = 7000;
var __initialized = false;
function initImgs(glry) {
	clearTimeout(__timer);
	__gallery = glry;
	__index = 1;
	__scroller = $('.hp-tabs-scrollbar .scroller');
	__last_img = glry.find('.tb_img:first-child');
	if (!__initialized) {
		$(".hp-tabs-cnt").find('.tb_img').css("opacity", "0");
		$(".hp-tabs-cnt").find('.tb_img').css("display", "block");
		__initialized = true;
	}
	$(".hp-tabs-cnt").find('.tb_img').css("opacity", "0");
	$(".hp-tabs-cnt").find('.tb_img').css("display", "block");
	__last_img.css("opacity", "1");
	//__timer = setTimeout("galimgauto()", __timeout);
	/*__gallery.find(".img_border").bind('mousewheel', function (event, delta) {
		clearTimeout(__timer);
		if(delta < 0)
			galimg(__index == 5 ? 1 : __index + 1);
		else
			galimg(__index == 1 ? 5 : __index - 1);
		return false;
	});*/

	galimg(0);
	return;

	glry.find('.tb_img').css("display", "none");
	__last_img.css("display", "block");

	//__scroller.css("right", (__lang == "he" ? 15 : 439) + "px");
	__scroller.animate({ right: (__lang == "he" ? 15 : 439) + "px" }, 400);
	__timer = setTimeout("galimgauto()", __timeout);
}

function galimg(indx) {
	//indx = __lang == "he" ? indx : 6 - indx;
	clearTimeout(__timer);
	if (indx == __index)
		return;

	__gallery.find(".img_border").unbind();

	var right = 15; //alert(indx);
	var img = __gallery.find(".tb_img").eq(__lang == "he" ? indx - 1 : 5 - indx);
	switch (__lang == "he" ? indx : 6 - indx) {
		case 1: case 0: case 6: __lang == "he" ? right = 15 : right = 439; break;
		case 2: __lang == "he" ? right = 119 : right = 333; break;
		case 3: __lang == "he" ? right = 226 : right = 226; break;
		case 4: __lang == "he" ? right = 333 : right = 119; break;
		case 5:  __lang == "he" ? right = 439 : right = 15; break;
	}//alert(right);
	__scroller.stop();
	__last_img.stop();
	
	__scroller.animate({ right: right + "px" }, 400);

	if (indx > 0) __gallery.find(".img_border").click(function () { img.click() });
	else __gallery.find(".img_border").click(function () { __gallery.find(".tb_img").eq(0).click() });

	__gallery.find(".img_border").bind('mousewheel', function (event, delta) {
		clearTimeout(__timer);
		if (__lang == "he") {
			if (delta < 0) galimg(__index == 5 ? 1 : __index + 1);
			else galimg(__index == 1 ? 5 : __index - 1);
		} else {
			if (delta > 0) galimg(__index == 5 ? 1 : __index + 1);
			else galimg(__index == 1 ? 5 : __index - 1);
		}
		return false;
	});

	//__last_img.clearQueue();
	/*__last_img.customFadeOut("fast", function () {
		img.customFadeIn(600);
	});*/

	if (indx > 0) {
		__last_img.animate({ opacity: 0 }, 700, function () {
			var i = 0;
			//__last_img.css("display", "none");
			//img.css("display", "block");
			//__prj_inamin = false;
		});
		img.animate({ opacity: 1 }, 700, function () {
			var i = 0; //__prj_inamin = false;
		});

		__last_img = img;
		__index = indx;
	} else {
		__gallery.find(".tb_img").eq(0).animate({ opacity: 1 }, 700, function () {
			var i = 0; //__prj_inamin = false;
		});
		__index = __lang == "he" ? 1 : 5;
		//alert(__index)
	}

	__timer = setTimeout("galimgauto()", __timeout);
}

function galimgauto() {
	if (__lang == "he")
		galimg(__index == 5 ? 1 : __index + 1);
	else
		galimg(__index == 1 ? 5 : __index - 1);
}

/****************************************************************************/

var __prj_index = 1;
var __prj_gallery = null;
var __prj_mousein = false;
var __prj_last_img = null;
var __prj_timer = 0;
var __prj_total = 0;
var __prj_timeout = 5000;
function initPrjImgs(glry, total) {
	clearTimeout(__prj_timer);
	__prj_gallery = glry;
	__prj_index = 1;
	__prj_total = total;
	__prj_last_img = glry.find('div:first-child');
	//prj_galimg(1);
	//return;
	//glry.find('div').css("display", "none");
	glry.find('div').css("opacity", "0");
	glry.find('.dummy').css("display", "none");
	__prj_last_img.css("display", "block");
	__prj_last_img.css("opacity", "1");

	__prj_timer = setTimeout("prj_galimgnext()", __prj_timeout);

	glry.find('div').bind('mousewheel', function (event, delta) {
		clearTimeout(__prj_timer);
		if (delta < 0)
			prj_galimg(__prj_index == __prj_total ? 1 : __prj_index + 1);
		else
			prj_galimg(__prj_index == 1 ? __prj_total : __prj_index - 1);
		return false;
	});
	$(".prj_box").hover(
		function () {
			__prj_mousein = true;
			clearTimeout(__prj_timer);
		},
		function () {
			__prj_mousein = false;
			__prj_timer = setTimeout("prj_galimgnext();", __prj_timeout);
		}
	);

	//alert(__prj_last_img.height());
	//var _height = parseInt(__prj_last_img.height());
	//$(".prj_box_in").height(_height +'px');
}

var __prj_inamin = false;
function prj_galimg(indx, total) {
	if (__prj_total <= 1) return;
	if (__prj_inamin) return;
	__prj_last_img.stop();

	__prj_inamin = true;
	clearTimeout(__prj_timer);
	if (indx == __prj_index)
		return;

	//__prj_gallery.find("div").unbind();
	var img = __prj_gallery.find("div").eq(indx - 1);


	$(".prj_box_in").stop();
	var _height = parseInt(img.height());
	_height = _height < 200 ? 200 : _height;
	$(".prj_box_in").animate({ height: _height }, 400);
	img.css("height", _height + "px");

	//__last_img.clearQueue();
	__prj_last_img.animate({ opacity: 0 }, 700, function () {
		__prj_last_img.css("display", "none");
		img.css("display", "block");
		__prj_inamin = false;
	});
	img.animate({ opacity: 1 }, 700, function () {
		__prj_inamin = false;
	});
//	__prj_last_img.customFadeOut("fast", function () {
//		img.customFadeIn(600);
//	});

	__prj_last_img = img;
	__prj_index = indx;

	if (!__prj_mousein)
		__prj_timer = setTimeout("prj_galimgnext();", __prj_timeout);
}

function prj_galimgnext() {
	if (__prj_total <= 1) return;
	prj_galimg(__prj_index == __prj_total ? 1 : __prj_index + 1);
}
function prj_galimgprev() {
	if (__prj_total <= 1) return;
	prj_galimg(__prj_index == 1 ? __prj_total : __prj_index - 1);
}
