(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = Math.ceil((ph-ah) / 2);
	$(this).css('padding-top', mh); // ili margin-top
	});
};
})(jQuery);

$(document).ready(function(){

	$(".manuf_naziv_cats").vAlign();
	
	/* http://jquery.malsup.com/cycle/ */
	$('#snippet_izdvojeno').cycle({
		pause: true,
		delay: 1000,
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

	$('form#snippet_ManufSelectForm').jqTransform({imgPath:'inc/js/jqtransformplugin/img/'});
	$('#snippet_ManufSelectForm_button').click(function(){
			if ($('#snippet_manselect').val()>0){
				href=$('form#snippet_ManufSelectForm').attr("action")+"/man"+$('#snippet_manselect').val()+"/"+$('#snippet_manselect option:selected').attr('title');
				window.location=href;
			} else {
				window.location=$('form#snippet_ManufSelectForm').attr("action")+"/";
			}
		});

		
		
	/* CONTACT FORM VALIDATION */
	// JS enabled -> enable cf_submit
	$("#cf_submit").removeAttr("disabled");

	// VALIDATE CONTACT FORM ON SUBMIT
	$("#cf").submit(function(){
		required=true;
		tmkvc=true;
		
		$("#cf .mailporuka, #cf #kontaktmailporuka").remove();
	
		$("#cf .fieldError").remove();
		
		$("#cf .required").each(function(){
			if ($(this).val()=="") {
				$(this).before("<span class='fieldError'>!</span>");
				required=false;
			}
		});
		
		$("#cf #cf_tmkvc").each(function(){
			ovaj=this;
			$.ajax({
				async: false,
				url: "/inc/php/tmkvcCheck.php",
				type: "post",
				data: "tmkvc="+$(this).val(),
				success: function(data){
					if (data=="false") {
						tmkvc=false;
						$(ovaj).before("<span class='fieldError'>!</span>");
					} else tmkvc=true;
				},
				error: function(){
					tmkvc=false;
					$(ovaj).before("<span class='fieldError'>!</span>");
				}
				});
		});
		
		
		return (required && tmkvc);
	});
	
		
		
		
		
		
		
		
	/*columnize manufacturers*/
	//$("#manufs_outer").columnize({ columns: 2 });
		
		
		
		
		
		
/*



	// VALIDATE CONTACT FORM ON SUBMIT
	$("#cf").submit(function(){

		required=true;
		tmkvc=true;
	
		$("#cf .fieldError").remove();
		
		$("#cf .required").each(function(){
			if ($(this).val()=="") {
				$(this).before("<span class='fieldError'>!</span>");
				required=false;
			}
		});
		
		$("#cf .tmkvc").each(function(){
			ovaj=this;
			$.ajax({
				async: false,
				url: "/inc/php/tmkvcCheck.php",
				type: "post",
				data: "tmkvc="+$(this).val(),
				success: function(data){
					if (data=="false") {
						tmkvc=false;
						$(ovaj).before("<span class='fieldError'>!</span>");
					} else tmkvc=true;
				},
				error: function(){
					tmkvc=false;
					$(ovaj).before("<span class='fieldError'>!</span>");
				}
				});
		});
		
		
		return (required && tmkvc);
	});
	
	
	
	*/


	
});


	



/* DEPO:


function cookieSet(name,value,days){
	// negativan days briše cookie
	var date = new Date();
	date.setTime(date.getTime ()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name + '=' + value + expires;
}
function cookieRead(name) {
	var cookiename = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length);
	}
	return null;
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}
function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}

*/
