﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!
//changed by Vladimir Buchgalter.
//changed by HM.
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var popupStatus2 = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});

		
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

function loadPopup2(img,text){
	//loads popup only if it is disabled
	//alert(img);
	if(popupStatus2==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		/* $("#popupGalery").css({
			"background":"url("+img+")"
		}); */
		
		$('#popupGaleryc').html('<img src="' + img + '" style="width:555px;max-height:550px;">');
		$('#popupText').html(text);
		
		$("#backgroundPopup").fadeIn("slow");
		$("#popupGalery").fadeIn("slow");
		popupStatus2 = 1;
		

		
		
		if ( !($.browser.msie && $.browser.version == 7.0) ){
			$("#body").css({
			"overflow-y": "hidden"
			});
		}else
		{
			$("html,body").css({
			"overflow-y": "hidden"
			});
		}
		
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}


function disablePopup2(){
	//disables popup only if it is enabled
	//alert(popupStatus2);
	if(popupStatus2==1){
		$("#popupGalery").fadeOut("slow");
		$("#backgroundPopup").fadeOut("slow");
		
		popupStatus2 = 0;
		
		if ( !($.browser.msie && $.browser.version == 7.0) ){
			$("#body").css({
			"overflow-y": "visible"
			});
		}else
		{
			$("html").css({
			"overflow-y": "scroll"
			});
		}
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var shadowHeight = document.documentElement.clientHeight;
	var windowHeight = document.documentElement.scrollTop;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight + 150,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": shadowHeight
	});
	
}

//centering popup
function centerPopup2(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var shadowHeight = document.documentElement.clientHeight;
	var windowHeight = document.documentElement.scrollTop;
	var popupHeight = $("#popupGalery").height();
	var popupWidth = $("#popupGalery").width();
	
	/* var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1; */
	
	/* if(window.devicePixelRatio==1)
	{
		windowHeight = document.body.scrollTop;
		
	} */
	//centering
	windowHeight = $(window).scrollTop();
	$("#popupGalery").css({
		"position": "absolute",
		"top": windowHeight + 20,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	/* $("#backgroundPopup").css({
		"height": shadowHeight
	}); */
	
}

//Function to check input of bug report
function CheckInput(){
	var hiddenValue = document.getElementById('url').value;
	var anti = document.getElementById('anti').value;
	var mailValue = document.getElementById('email_reporter').value;
	var descriptionValue = document.getElementById('description').value;
	var mail_reg = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(hiddenValue != ""){
		return false;
	}

	if(anti != ""){
		return false;
	}
	
	if(descriptionValue == ""){
		alert('אנא הכנס את תאור התקלה');
		return false;
	}
	
	if(mailValue == ""){
		alert('אנא הכנס כתובת דואר אלקטרוני');
		return false;
	}
	
	if(mailValue != ""){
		if(!mailValue.match(mail_reg)){
			alert('אנא הכנס כתובת דואר אלקטרוני תקינה');
			return false;
		}			
	}
		
	return true;
}

$(document).ready(function(){

	/**************************************************************************/

	$('#addcomment').click(function () {
		$('#addcommentform').show('slow');
	});
	
	$('.commOptions_AddComm').click(function () {
		$('#addcommentform').show('slow');
	});
	
	$('.commOptions_Hide').click(function () {
		var clickedItem = $(this).attr("id");
		var regex_num = clickedItem.match(/[\d\.]+/g);
		var hideDiv = '#comm_' + regex_num[0];
		$(hideDiv).hide('slow');
		$('#addcommentform').hide('slow');
	});
		
	$('#invalid_captcha').click(function () {
		$('#addcommentform').show('slow');
		$('#comm_message').remove();
	});

	$('.close').click(function () {
		$('#addcommentform').hide();
	});
	
	$('.author').click(function () {
		var clickedItem = $(this).attr("id");
		var showDIV = '#comm_' + clickedItem;
		$(showDIV).show('slow');	
	});
	
	/**************************************************************************/

	/**************************************************************************/
	/**************************************************************************/
	//Search Results
	
	$('.showMore').click(function () {
		if($('.showMore').text() == "הסתר..."){
			$('#hiddenItems').hide();
			$('.showMore').text("הצג עוד תוצאות...");
		}
		else{
			$('#hiddenItems').show();
			$('.showMore').text("הסתר...");	
		}		
	});
	
	$('.showMore2').click(function () {
		if($('.showMore2').text() == "הסתר..."){
			$('#hiddenItems2').hide();
			$('.showMore2').text("הצג עוד תוצאות...");
		}
		else{
			$('#hiddenItems2').show();
			$('.showMore2').text("הסתר...");	
		}		
	});
	
	
	/**************************************************************************/
	
	// Search field value change
	$('#search_box .field').focus(function () {

		if($(this).attr('value') == 'מה ברצונך למצוא?') {
			$(this).attr('value', '');
		}

	});

	$('#search_box .field').blur(function () {

		if($(this).attr('value') == '') {
			$(this).attr('value', 'מה ברצונך למצוא?');
		}

	});

	/**************************************************************************/
	
	$("#bugReport").click(function(){
		centerPopup();
		loadPopup();
	});
				
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	
	$("#PhotoClose1").click(function(){
		disablePopup2();
	});
	
	$("#PhotoClose2").click(function(){
		disablePopup2();
	});

	$("#backgroundPopup").click(function(){
		disablePopup();
		disablePopup2();
	});

	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopup2();
		}
	});
});
