function clearText(theField)
{
if (theField.defaultValue == theField.value)
theField.value = '';
}

function addText(theField)
{
if (theField.value == '')
theField.value = theField .defaultValue;
}

jQuery.noConflict();

/*
  * Izjednačavanje visina kolona
*/
jQuery(document).ready(function(){

       var najvislje = 0;
       jQuery("div.poljevisina").each(function (i) {
            if (jQuery(this).height() >= najvislje) {
              najvislje = jQuery(this).height();
            }
       });
       jQuery("div.poljevisina").each(function (i) {
            jQuery(this).height(najvislje);
       });

       var najvislje = 0;
       jQuery("div.poljevisina1").each(function (i) {
            if (jQuery(this).height() >= najvislje) {
              najvislje = jQuery(this).height();
            }
       });
       jQuery("div.poljevisina1").each(function (i) {
            jQuery(this).height(najvislje);
       });
});

jQuery(document).ready(function(){
	jQuery("#menu").unops_menu();

    jQuery(".download_now").tooltip({
      relative: true,
      offset: [-25, 30],
      effect: 'slide'

      }).dynamic({ bottom: { direction: 'down', bounce: true } });

/* GALLERIES */
		jQuery(".big_gallery").unops_gallery({  
            photos: ".item",
			thumbs: ".gallery_navigation a",
			buttonNext: ".gallery_button_next",
			buttonPrev: ".gallery_button_prev",
			buttonPlayPause: ".button_play_pause",
			easing: "easeInOutQuad",
			speedIn: 400,
			speedOut: 600
		});

// Simply Spy News Rotator
   //     jQuery(function () {
   //         jQuery('ul.spy').simpleSpy();
   //     });
        jQuery(function () {
              jQuery('ul.spy').simpleSpy().bind('mouseenter', function () {
                  jQuery(this).trigger('stop');
              }).bind('mouseleave', function () {
                  jQuery(this).trigger('start');
              });
          });
          jQuery(function () {
              jQuery('ul.spylist').simpleSpy(5,6000).bind('mouseenter', function () {
                  jQuery(this).trigger('stop');
              }).bind('mouseleave', function () {
                  jQuery(this).trigger('start');
              });
          });
});

/*******************************************************************************
  Simply Spy - http://jqueryfordesigners.com/simple-jquery-spy-effect/
  Simply News rotate
*/
(function ($) {

$.fn.simpleSpy = function (limit, interval) {
    limit = limit || 3;
    interval = interval || 6000;

    return this.each(function () {
        // 1. setup
            // capture a cache of all the list items
            // chomp the list down to limit li elements
        var $list = $(this),
            running = true,
            items = [], // uninitialised
            currentItem = limit,
            total = 0, // initialise later on
            height = $list.find('> li:first').height();

        // capture the cache
        $list.find('> li').each(function () {
            items.push('<li>' + $(this).html() + '</li>');
        });

        total = items.length;

        $list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit });

        $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();
        $list.bind('stop', function () {
            running = false;
        }).bind('start', function () {
            running = true;
        });

        // 2. effect
        function spy() {
          if (running) {
            // insert a new item with opacity and height of zero
            var $insert = $(items[currentItem]).css({
                height : 0,
                opacity : 0,
                display : 'block'
            }).prependTo($list);

            // fade the LAST item out
            $list.find('> li:last').animate({ opacity : 0}, 1000, function () {
                // increase the height of the NEW first item
                $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);

                // AND at the same time - decrease the height of the LAST item
                // $(this).animate({ height : 0 }, 1000, function () {
                    // finally fade the first item in (and we can remove the last)
                    $(this).remove();
                // });
            });

            currentItem++;
            if (currentItem >= total) {
                currentItem = 0;
            }
           }
            setTimeout(spy, interval)
        }

        spy();
    });
};

})(jQuery);
/*
  * MENU ***
*/

(function($) {
	$.fn.unops_menu = function(options) {
		var defaults = {
			autoPosition: false,
			limitValue: "wrapper",
			easing: "easeOutQuint",
			speedIn: 100,
			speedOut: 100
		};

		var settings = $.extend({}, defaults, options);

		/**/

		return this.each(function () {
			var $root = $(this);
			var $mainmenu = $(">ul", this);
			var $headers = $mainmenu.find("ul").parent();
			var $limitValue = (settings.limitValue == "document") ? $(window).width() : 960;

			/**/

			$headers.each(function () {
				var $curobj = $(this);
				var $subul = $(this).find('ul:first');
				var $ul = $("ul", $curobj);

				$("ul ul", $root).css({"display": "none", "paddingTop": "0px"}).find("li:first").css({"marginTop": "15px"});
				$("ul ul ul", $root).find("li:first").css({"marginTop": "5px"});

				/**/

				function getProperty($li, $ul) {
					$li.dimensions = {
						w: $li.offsetWidth,
						h: $li.offsetHeight,
						subulw: $ul.outerWidth(),
						subulh: $ul.outerHeight()
					}
					return $li.dimensions;
				}

				function showMenu ($element) {
					$element.css({visibility:'visible'}).slideDown(settings.speedIn);
				}

    			function hideMenu ($element, $current) {
    				$element.slideUp(settings.speedIn, function() {
    					$element.hide();
    				});
    				setTimeout(function() {
        				$current.stop().animate({
        					borderBottomWidth: "5px"
        				}, settings.speedIn + 100, "easeInOutSine");
   				 	}, 100);
    			}

				/**/
				$curobj.click(function() {
					var $targetul = $(this).find("ul:first");
					$targetul.hide();
				});
				$curobj.hoverIntent(function() {
					closeOptionsMenu();
					getProperty(this, $subul);

					if($(this).find("current")) {
						$(this).stop().animate({borderBottomWidth: "0px"}, 1, "easeInOutSine");
					}

					var $targetul = $(this).find("ul:first");
					var $offset = $(this).offset();

					if($curobj.parents("ul").length == 1) {
						$ul.css({visibility:'hidden'});
						this.firstLevel = true;
						$subul.css({top: 23 + "px"});
					} else {
						this.firstLevel = false;
						$subul.css({top: -5 + "px"});
					}

					if(this.firstLevel) {
						var menuleft = 0;
					} else {
						var menuleft = this.dimensions.w;
					}

					if(($offset.left + menuleft + this.dimensions.subulw) > $limitValue && !this.firstLevel) {
						menuleft = -(this.dimensions.w);
					}

					if(settings.autoPosition == true) {
						$targetul.css({left:menuleft + "px"});
					}
					showMenu($targetul);
				}, function() {
					var $targetul = $(this).find("ul:first");
					hideMenu($targetul, $(this));
				});
			});
		});
	};
})(jQuery);

/*
  * GALLERY ***
*/

(function($) {
	$.fn.unops_gallery = function(options) {
		var defaults = {
			photos: "",
			thumbs: "",
			buttonNext: "",
			buttonPrev: "",
			buttonPlayPause: "",
			buttonClose: "",
			/**/
			autoStart: true,
			firstClick: true,
			toogle: false,
			/**/
			timer: 6000,
			easing: "",
			speedIn: 400,
			speedOut: 200
		};

		var settings = $.extend({}, defaults, options);

		/**/

		return this.each(function() {
			var $root = $(this);
			var $items = $(settings.photos , $root);
			var $thumbs = $(settings.thumbs);
			var $totItems = $items.length;
			var $movies = [];
			var $status = "";
			var $index = 0;
			var $interval = "";

			/**/

			function slideshow(index) {
				if(index){
					var id = index;
				} else {
					var id = 0;
				}
				$interval = setInterval(
					function() {
						play(id, "next");
					}, settings.timer
				);
			}

			function play(index, verse) {
				var id = index;
				if(verse == "next" || verse == undefined) {
					if(id < ($thumbs.length - 1)) {
						id++;
					} else {
						id = 0;
					}
				} else {
					if(id > 0) {
						id--;
					} else {
						id = ($thumbs.length - 1);
					}
				}
				$thumbs.filter(":eq("+ id +")").trigger("click", [true]);
			}

			function positionNavigation(next, prev, nav, gallery) {
				var left = (gallery.width() / 2) - (nav.width() / 2);
				var top = (gallery.height() / 2) - (next.height() / 2);

				next.css("margin-top", top);
				prev.css("margin-top", top);
				nav.css("margin-left", left);
			}

			function changeThumbs($current) {
				for(i = 0; i < $thumbs.length; i++) {
					$thumbs.filter(":eq("+ i +")").removeClass("current");
				}
				$current.addClass("current");
			}

			if(settings.autoStart == true) {
				$status = "play";
				$(settings.buttonPlayPause + " img").attr('src', 'images/skin/button_pause.png');
			} else {
				$status = "pause";
			}

			if($("body").find("#project_details").length > 0) {
				$thumbs.css("cursor", "pointer");
			}

			/**/

			$thumbs.each(function(i) {
				$movies[i] = $items.filter(":eq(" + i + ")").find(".movie").html();

				$(this).click(function() {
					var $new_item = $items.filter(":eq(" + i + ")");
					var $media = $items.filter(":eq(" + i + ")").find(".movie").length;
					var $new_height = $new_item.height();

					this.id = i;
					$index = this.id;

					if($interval) {
						clearInterval($interval);
					}
					if($media == 0 && $status == "play" && $totItems > 1) {
						slideshow(this.id);
					}

					if($new_item.css("display") == "none") {
						if($items.filter(":visible").find(".movie")) {
							$items.find(".movie").empty();
						}
						if($media > 0) {
							$new_item.find(".movie").html($movies[this.id]);
						}
						$items.filter(":visible").fadeOut(settings.speedOut, settings.easing);
						$new_item.fadeIn(settings.speedIn, settings.easing);

						if($("#project_details").length > 0) {
							var tot = $new_item.find(".item").length;
							var width = (15 * tot) + 80;
							$new_item.find(".gallery_navigation").css("width", width);
							if($("body").find(".portfolio_big_gallery").length > 0) {
								positionNavigation($new_item.find(".gallery_button_next"), $new_item.find(".gallery_button_prev"), $new_item.find(".gallery_navigation"), $new_item.find(".big_gallery"));
							}
							if($("body").find(".portfolio_small_gallery").length > 0) {
								positionNavigation($new_item.find(".gallery_button_next"), $new_item.find(".gallery_button_prev"), $new_item.find(".gallery_navigation"), $new_item.find(".small_gallery"));
							}
						}
					}

					if(settings.toogle == true) {
						$root.show().animate({
							"height" : $new_height
						}, settings.speedIn, settings.easing, function() {
							$('#portfolio_navigation').slideDown(settings.speedIn);
						});
						$('html:not(:animated),body:not(:animated)').animate({ scrollTop: 0 }, settings.speedIn, settings.easing);
						$('.breadcrumb').animate({ "paddingTop": "0px"}, settings.speedIn, settings.easing);
					}

					changeThumbs($(this));

					return false;
				});
			});

			if($totItems > 1) {
				var width = (15 * $totItems) + 80;
				$root.find(".gallery_navigation").css("width", width);
				var left = ($root.width() / 2) - ($root.find(".gallery_navigation").width() / 2);
				var top = ($root.height() / 2) - ($(settings.buttonNext).height() / 2)-30;

				/* NAVIGATION */

				$root.find(".gallery_navigation").show().css("margin-left", left);

				/* BUTTON PLAY/PAUSE */

				$(settings.buttonPlayPause, $(this)).click(function() {
					if($status == "play") {
						$status = "pause";
						clearInterval($interval);
						$("img", $(this)).attr('src', 'images/skin/button_play.png');
					} else {
						$status = "play";
						play($index, "next");
						$("img", $(this)).attr('src', 'images/skin/button_pause.png');
					}
				});

				/* BUTTONS NEXT / PREV / CLOSE */

				$(settings.buttonNext).show().css("margin-top", top).click(function() {
					play($index, "next");
				});
				$(settings.buttonPrev).show().css("margin-top", top).click(function() {
					play($index, "prev");
				});
			} else {
				$root.find(".gallery_navigation").hide();
			}

			/* BUTTON CLOSE */

			$(settings.buttonClose, $items).click(function() {
				closeProjects();
			});

			/* FIRST CLICK */

			if(settings.firstClick) {
				setTimeout(function() {
        			$thumbs.filter(":eq(0)").trigger("click", [true]);
   				}, 500);
			}
		});
	}
})(jQuery);



