﻿jQuery.noConflict();

(function($){

	// izbornik kategorija
	$(function(){
		var subMenu = ">.SubMenuBar>.SubMenu";
		$(".MenuContainer > .MenuItem > a, .TopMenuBar .MenuItem > a")
			.bind("mouseenter",	function(){
				var $item = $(this).parent();
				if ($item.hasClass("active")) {
					return;
				}
					
				$item.addClass("active");
				
				$(subMenu, $item)
					.stop(true, true)
					.show()
					.css({
						top: -1 * $(subMenu, $item).height()
					})
					.animate({
						top: 0
					}, 200, "swing")
					.parent()
						.show();
				
				$item.siblings(".active").find(subMenu)
					.stop(true, true)
					.each(function(i, elm) {
						$(elm).animate({
							top: -1 * $(elm).parent().height()
						}, 300, "swing", function() {
							$(this).parent().parent().removeClass("active");
							$(this).parent().hide();
						});
					});
			})
			.parent().bind("mouseleave", function(){
				var $this = $(this);
				if ($(subMenu, $this).length === 0) {
					$this.removeClass("active");
				}
				
				$(subMenu, $this)
					.delay(500)
					.each(function(i, elm) {
						$(elm).animate({
							top: -1 * $(elm).parent().height()
						}, 300, "swing", function() {
							$(this).parent().parent().removeClass("active");
							$(this).parent().hide();
						});
					});
			});
			
			
		/* izbornik kategorija u side paneu */
		// označi samo aktivnu kategoriju
		$(".CM_ItemSel:has(.CM_ItemSel) > a").addClass("parent");
		
		// fade boja na hover
		$(".CM_Item a").not(".CM_ItemSel > a").hover(
			// mouse over
			function() {
				$(this).stop(true, true).animate({
					color: "#c8001e"
				}, 30);				
			}, 
			// mouse out
			function() {
				$(this).stop(true, true).animate({
					color: "#c8c8c8"
				}, 300);
			}
		);
		
		/* layout izbornika podkategorija */
		$(".CM2_Container > .CM2_Item:nth-child(4n+1)").addClass("clear");
	});
	
	$(function() {
		$(".button").hover(
			// mouse over
			function() {
				$(this).stop(true, true).animate({
					color: "#c8001e"
				}, 30);				
			}, 
			// mouse out
			function() {
				$(this).stop(true, true).animate({
					color: "#ffffff"
				}, 300);
			}
		);
	});
	
	// google maps
	$(function() {
		var markers = [];
		$(".servis-item").each(function(i, elm) {
			var $elm = $(elm);
			
			markers.push({
				latitude: $elm.find(".lat").text(),
				longitude: $elm.find(".long").text(),
				html: $elm.find(".servis-template").html()
			});
		});
		
		$("#servisi-map").gMap({
			scrollwheel: true,
			zoom: 8,
			markers: markers,
			controls: {
				panControl: true,
				zoomControl: true,
				mapTypeControl: true,
				scaleControl: true,
				streetViewControl: true,
				overviewMapControl: true
			}
		});
	});
	
	// fancybox
	$(function () {
		$(".product-image a").fancybox({
			titlePosition: 'inside'
		});
	});
	
	// slideshow
	$(function () {
		$("#slideshow [id$=lblContent] p").not(":has(img)").remove();
		$("#slideshow [id$=lblContent]").cycle({
			fx: 'scrollLeft',
			timeout: 7000,
			pause: 1
		})
	});
	
}(jQuery));

