$(document).ready(function(){	
	$("#footer .email").focus(function(){
		$(this).removeClass("inactive").val("");
	});
	
	$("#search-what").sSelect();
	
	$(".navigation9 ul:first").addClass("look-left");	
});

$(document).ready(function(){
	var elements_length = 0;
	var nav_length = 989;
	$("#navigation ul:first li").each(function(){
		elements_length = elements_length + $(this).outerWidth();
	});
	
	if(elements_length < nav_length) {
		var raz = nav_length - elements_length;
		var raz_new = parseInt(raz/2);
		$(".navigation9 a:first").css({ paddingLeft : 10+raz_new, paddingRight: 10+raz_new });
	}
});

$(document).ready(function(){
	var najvisi = 0;
	$(".column h3").each(function(){
		if($(this).height() > najvisi) { najvisi = $(this).height(); }
	});
	$(".column h3").css("height", najvisi);
});


$(document).ready(function(){
	$(".listh a").click(function(){
		$.get($(this).attr("rel"), function(data) {
			$(".products-table").html(data);
		});
		return false;
	});
});

$(document).ready(function() {
    $('#slides-1').cycle({
		fx: 'fade',
		timeout: 6000,
		pager:  '#controls-1' 
	});
	
	$('#slides-2').cycle({
		fx: 'fade',
		timeout: 6000,
		pager:  '#controls-2' 
	});
	
	$('#slides-3').cycle({
		fx: 'fade',
		pager:  '#controls-3' 
	});
	
	$('#catalog-slides').cycle({
		fx: 'fade',
		pager:  '#catalog-controls' 
	});
});

$(document).ready(function(){
	$("#sidebar-slider .top a").click(function(){
		
		$("#sidebar-slider .top a").removeClass("active");
		var id = $(this).attr("id");
		$("#"+id).addClass("active");
		
		$("#sidebar-slider .sld").css({ display: "none" });
		
		$("#s"+id).css({ display: "block" });
		
		return false;
		
	});
});

$(document).ready(function(){
	
	$(".upit").click(function(){
		$.get(phrasebook.URL_ROOT+"/popup_upit.html", function(data){
			$('html, body').animate({scrollTop:140}, 'slow');
			$("body").append(data);
		});
		return false;
	});
	
	$("#upit .close").live('click', function(){
		$("#overlay").fadeOut("slow", function(){ $(this).remove(); });
		return false;
	});
	
});

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(document).ready(function(){
	jQuery('#slider').jcarousel({
        auto: 0,
        wrap: 'last',
		scroll: 1,
		initCallback: mycarousel_initCallback
    });
});


$(document).ready(function(){
	
	var sl2_p = 0;	
	var sl2_ml = $(".sl2-sss ul li > div").size() * 240; sl2_ml = sl2_ml * (-1); /*alert(sl1_ml);*/ 
	
	$("#sl2-l").click(function(){
	
		var end;
		if(parseInt($(".sl2-sss ul li > div").size()) % 3 != 0) {
			var mod = parseInt($(".sl2-sss ul li > div").size() % 3 );
			end = ($(".sl2-sss ul li > div").size() * 240 - (mod * 240 + 240 ) ) * (-1);
			end = end.toString() + "px";
			
			if($(".sl2-sss ul").css("margin-left") == end) { return false; }
		}
	
		sl2_p = sl2_p - 240;
		
		if(sl2_p > ( sl2_ml ) ) {
		$(".sl2-sss ul").animate({ marginLeft: sl2_p +"px" }, 1000);
		}
		
		return false;
	});
	
	$("#sl2-r").click(function(){
		if($(".sl2-sss ul").css("margin-left") == "0px") { return false; }
	
		sl2_p = sl2_p + 240;
		//alert(-1 *( sl1_ml-150)); 
		if(sl2_p < 705  ) { 
		$(".sl2-sss ul").animate({ marginLeft: sl2_p +"px" }, 1000);
		}
		
		return false;
	});
});


$(document).ready(function(){
	var lengths = new Array();
	var move_it = 0;
	var total_c = $(".brands li").size();
	$(".brands li").each(function(i){
		lengths.push($(this).outerWidth());
	});
	
	$("#bs-1").click(function(){
		if((parseInt($(".listh ul").css("left"))) < -600) { return false; }
		
		var tmp = lengths.shift();
		move_it = move_it - tmp;
		lengths.push(tmp);
		$(".brands ul").animate({ left: move_it + "px" }, 1000);
		
		return false;
	});
	
	$("#bs-2").click(function(){
		if($(".listh ul").css("left") == "0px") { return false; }
		
		var tmp = lengths.pop();
		move_it = move_it + tmp;
		lengths.unshift(tmp);
		$(".brands ul").animate({ left: move_it + "px" }, 1000);
		
		return false;
	});
});


$(document).ready(function(){
	
	$(".pic-slider a").click(function(){		
		$(".main-pic img").attr("src", $(this).attr("href"));
		
		$(".pss a").removeClass("active"); $(this).addClass("active");
		
		return false;
	});
	
	var pl2_p = 0;	
	var pl2_ml = $(".pss > a").size() * 46; pl2_ml = pl2_ml * (-1);
	$("#pas-l").click(function(){
		pl2_p = pl2_p - 49;
		
		if(pl2_p > ( pl2_ml ) ) {
		$(".pss").animate({ left: pl2_p +"px" }, 500);
		}
		
		return false;
	});
	
	$("#pas-r").click(function(){
		pl2_p = pl2_p + 49; 
		//alert(-1 *( sl1_ml-150)); 
		if(pl2_p < 49  ) { 
		$(".pss").animate({ left: pl2_p +"px" }, 500);
		}
		
		return false;
	});
});

$(document).ready(function(){
	$(".trg-popup .slide").click(function() {
	
		$("#popup-wrapper").remove();
	
		var pos = $(this).offset();		
		var popup = '<div id="popup-wrapper"><div class="popup-content">';
		popup = popup + $(".popup-meta", this).html();
		popup = popup + '</div><div class="popup-end"></div></div>';
		
		$("body").append($(popup).css({ top: (pos.top - 55), left: (pos.left + 65 ) }));
		
		return false;
		
	});
	
	$(document).click(function(){ $("#popup-wrapper").remove() });
});

$(document).ready(function(){
	/*$(".featured-box img").each(function(){
		var mt = 70 - parseInt($(this).height()/2);
		$(this).css({ marginTop: mt });
	});*/
});

$(document).ready(function(){
	var najvisi = 0;
	$("#proizvodi-02 .proizvod").each(function(){
		if($(this).height() > najvisi) { najvisi = $(this).height(); }
	});
	$("#proizvodi-02 .proizvod").css("height", najvisi);
});

$(document).ready(function(){
	var najvisi = 0;
	$(".top .us2 h3").each(function(){
		if($(this).height() > najvisi) { najvisi = $(this).height(); }
	});
	$(".top .us2 h3").css("height", najvisi);
});

$(document).ready(function() {
	//if($(".paginacija-01").html() != null && $(".paginacija-01").html().trim() == "") { $(".paginacija-01:first").remove(); }
});

/* FAVORITI */
function addToFavorites() {
	var page_title = document.title;
	var url = document.location.href
	if(window.sidebar)
	{ window.sidebar.addPanel(page_title, url,''); 
	} else if(window.opera) 
	{ var a = document.createElement('A'); a.rel = 'sidebar'; a.target = '_search'; a.title = page_title; a.href = url; a.click(); 
	} else if(window.external)
	{ window.external.AddFavorite(url, page_title); 
	} else { } 
}

function addToDelicious() {
	var to = "http://del.icio.us/post?url=" + encodeURIComponent(document.location.href) + "&title=" + document.title;
	window.location = to;
}

function addToFacebook() {
	var to = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(document.location.href) + "&t=" + document.title;
	window.location = to;
}

function addToTwitter() {
	var to = "http://twitter.com/home?status=" + document.title + " -- " + encodeURIComponent(document.location.href);
	window.location = to;
}

$(document).ready(function(){
	$(".wsh2:last td").addClass("wsh3");
});

$(window).load(function(){
	$(".newList").append('<li class="newListEnd"></li>');
});

$(document).ready(function(){
	$("a.print").click(function(){
		window.print();
	});
});

$(document).ready(function(){
	$(".selectedTxt").text(jQuery.trim($(".selectedTxt").text()).replace("&nbsp;", ""));
});

$(document).ready(function(){
	$(".newList a").click(function(){
		$(".selectedTxt").text(jQuery.trim($(".selectedTxt").text()).replace("&nbsp;", ""));
	});
});

var map;
var map_infowindow;
$(document).ready(function(){
    if( $('#gmap').length > 0 ){
            map = new google.maps.Map(document.getElementById("gmap"), {
                zoom: 7,
                center: new google.maps.LatLng( 44.85, 16.51 ),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            });
            map_infowindow = new google.maps.InfoWindow({
                content: 'map_infowindow'
            });
    }
  $("a.changeMap").click(function(e){
    e.preventDefault();
    var koordinate = $(this).attr("href").split("|");
    var lat = koordinate[0].substr(1);
    var lng = koordinate[1];
    map.setCenter(new google.maps.LatLng( lat, lng ));
    map.setZoom( 15 );
  });
});

//LOCATION MAP POPUP
$(document).ready(function() {
    $("#location-map ul a,#location-map ul span").click(function(){
        $("#location-popup").remove();
        var data="<strong>"+$(this).parents("li:first").attr("title")+"</strong>";
        $(this).parents("li:first").find("dl").each(function(){
            data = data+"<b>"+$(this).find("dt").text()+"</b>";
            $(this).find("dd").each(function(){
                data = data+$(this).html()+"<br />";
            });
        });
        $("body").append('<div id="location-popup"><div class="bkg-1"><div class="bkg-2"><img class="close" src="images/close.gif" alt="zatvori" title="zatvori" />'+data+'</div></div></div>');
        var offset = $(this).parents("li:first").find("span").offset();       
        $("#location-popup .close").click(function(){ $("#location-popup").remove(); });
        
        $("#location-popup").css({left: offset.left - 105, top: offset.top-$("#location-popup").height()-10 }).show();
    });
});

$(document).ready(function(){
	$("#work_order_code").click(function(){
		$(this).val("");
	});
});


$(document).ready(function(){

	$(".specs tr:even td").css("background", "#f4f4f4");
	
	$(".specs tr").each(function() {
		
		if($("td:first", this).height() > $("td:last", this).height()) {
			
			var raz = $("td:first", this).height() - $("td:last", this).height();
			$("td:last", this).css({"padding-top": raz, "height": ($("td:last", this)-raz) });
			
			//$("td", this).css("height", $("td:first", this).height());
		
		} else {
			$("td", this).css("height", $("td:last", this).height());
		}
		
	});
	
});
