//GENERAL JAVASCRIPT
$("html").addClass("js");

$(document).ready(function() {
    $(".table-type-2 tr:last").addClass("last");
    $("#home_row_wrapper .row_3 .column02 ul li:last").addClass("last");
    $("#wrapper #home_row_wrapper .row_3 .column03 p:first").addClass("first");
    $(".area-item:last").addClass("last");
		
		
    $(".table-type-2 tr").each(function(){
        $(this).find("td:last").addClass("last");
    });
    
    if(parseFloat($("#column-1").height())<555){
        $("#column-1").height("555px");
    }
		
	//table info-block same height
	$('.table-type-1 tr').each(function(){
		var currTallest = 0;
		//alert($(this).find('.info-block').length);
		$(this).find('.info-block').each(function(i){
			if ($(this).height() > currTallest) { currTallest = $(this).height(); }
		});
		$(this).find('.info-block').css({'height': currTallest}); 
	});
	
	
    //main-nav dropdown width
		var titleCount = $("#top-navigation ul li.nav_2 ul li.title").length;
		if ( titleCount == 1 ) { $('#top-navigation ul li.nav_2 ul').css("width", "235px"); }
		$("#top-navigation ul li ul li:last").addClass("last");
		
/* 	$(".table-type-1 a.imgWrapper span.sliderWrapper img").click(function(e)
		{
			e.preventDefault();
			window.location=$(this).closest("a").attr('href');
		}); */

});

//LIGHTBOX
$(document).ready(function() {
    $(".lightbox").lightBox();
    $(".lightboxPhoto").lightBox();
    $(".lightboxGround").lightBox();
    $(".lightboxModels").lightBox();
    $(".lightboxPhases").lightBox();
		$("a.istra-lightbox").each(function() { $(this).lightBox(); });

});

//REAL ESTATE DETAIL TABS & GALLERY
$(document).ready(function() 
{
	$(".multimedia-box > div:eq(0)").show().siblings().hide();
	$(".tabs li:eq(0)").addClass("active").siblings().removeClass("active");
	$("ul.tabs li").click(function(){
		
		var index = $(".tabs li").index(this);
		$(".multimedia-box > div:eq("+index+")").show().siblings().hide();
		$(this).addClass('active').siblings('li').removeClass('active');

	});
	
	$(".multimedia-box > div").each(function(){
		
		var box = this;
		
		$(box).find('a.first').unbind('click').click(function(e)
		{
			e.preventDefault();
			$(box).find('.container ul li a.hidden[rel='+ $(this).attr('rel') +']').click();
		});
		

		
		$(box).find('.container ul li a:not(.hidden)').unbind('click').click(function(e)
		{
			e.preventDefault();
			var rel = $(this).attr("rel");
			var href = $(this).attr("href");
			var count = $(this).attr("class");
			var mainImg = $(box).find('img:first');
			$(mainImg).attr('src', rel);
			$(mainImg).parent().attr({href: href, rel: count});
		});
		
		var containerHeight = parseFloat($(box).find('.container').css('height'));
		var slideCount = $(box).find('.container ul').length;
		var currSlide = 1;

		if (slideCount < 2) 
		{
			$(box).find('.nav').hide();
		} 
		else
		{
			$(box).find('.nav .txt').text(currSlide+'/'+slideCount);
			$(box).find('.nav .up, .nav .down').click(function()
			{
				var button = $(this);
				
				if ( button.is('.up'))
				{
					
					if (currSlide <= 1)
					{
						return false;
					}
					slideAnim = '+='+containerHeight;
					currSlide--;
				}
					
				if ( button.is('.down') )
				{
					if (currSlide >= slideCount)
					{
						return false;
					}
					slideAnim = '-='+containerHeight;
					currSlide++;
				}
				
					$(box).find('.container ul:first').animate({ marginTop: slideAnim }, 400,function(){
					
						$(box).find('.nav .txt').text(currSlide+'/'+slideCount);
					
					});
			});
		}
	});
});



//REAL ESTATE LIST IMG SLIDER
$(document).ready(function()
{
	$(".cell").each(function () 
	{
		var slideCount = $(this).find('img.slider-item').length;
		
		if (slideCount >= 2)
		{
			$(this).find('.image-slide-nav').show();
			var slideCurr = 1;
			$(this).find('.image-slide-nav .text').text(slideCurr + '/' + slideCount);
			var slideWidth = $(this).find('img.slider-item').outerWidth('true');
			var sliderWrapperWidth = slideCount * slideWidth;
			$(this).find('.imgWrapper').css('width', sliderWrapperWidth);
			
			$(this).find('.image-slide-nav').find('.left, .right').click(function()
			{
				var button = $(this);
	
				if ( button.is('.left') && (slideCurr <= slideCount) && (slideCurr > 1))
				{
					slideCurr--;
					slideAnim = -(slideWidth*(slideCurr-1));
				}
				else if ( button.is('.right') && (slideCurr < slideCount) )
				{
					slideAnim = -(slideWidth*slideCurr);
					slideCurr++;
				}

				$(this).parents('.cell').find('.imgWrapper').animate({ marginLeft: slideAnim }, 600 );
				$(this).siblings('.text').text(slideCurr + '/' + slideCount);
			});
		}			
	});
});


// REALESTATE DETAIL OPIS-LOKACIJA TAB SWITCH
$(document).ready(function(){
/*
	var h1 = $("#op-lokacija").height();
	var h2 = $("#op-opis").height();
	
	$(".opis-holder").height( ((h1>h2) ? h1 + "px" : h2 + "px" )  );
*/	
	$(".switch-top a:first").addClass("active");
	$(".opis-switch .opis-holder:first").css({ display: "block" });
	
	$(".switch-top a").click(function(){		
		var rel = $(this).attr("rel");
		$(this).addClass("active");
		
		if(rel == "opis") {			
			$('.switch-top a[rel="lokacija"]').removeClass("active");
			$("#op-lokacija").css({ display: "none" });
			$("#op-opis").css({ display: "block" });
		} else {
			$('.switch-top a[rel="opis"]').removeClass("active");
			$("#op-opis").css({ display: "none" })
			$("#op-lokacija").css({ display: "block" });
		}
		
		return false;
	});
	
});






//TABLE ROW HEIGHT & SLIDE-UP <p> boxSpecialOffer
$(document).ready(function() {
	$('table.table-type-2 tr').each(function() {
		var maxH = 0;
		$(this).find('td .cell').each(function() {
			var currH = $(this).height();
			if (currH > maxH) { maxH = currH; }
		});
		$(this).find('td .cell').height(maxH);
	});
});


//SUB-NAV LI POSITIONING
$(document).ready(function() {
	if (!$.browser.msie) {
		var wi = 0;
		$('.sub-nav ul li').each(function() {
			wi += $(this).width();
		});
		if (wi<716) {
			$('.sub-nav ul li a:not(:last)').css('margin-right', (716-wi)/6 + 21 + 'px');
			$('.sub-nav ul li a:last').css('margin-right', '0px');
		}
	}
});


//HOME SPECIAL_OFFER_SHOW
var slideNo = '';
$(document).ready(function(){
	$('#special-offer-show li:first').addClass('on');
	var intSpeed = 6000;
	var int = setInterval('autoPlay()', intSpeed);
	
	$('#special-offer-show .txt').hover(function() {
		$(this).parent().siblings().removeClass('on');
		$(this).parent().addClass('on');
		clearInterval(int);
	}, function(){
		int = setInterval('autoPlay()', intSpeed);
	});

	var liCount = $('#special-offer-show ul li').length;
	var liVisible = 3;
	
	if (liCount <= liVisible) { 
		$('#special-offer-down').hide(); 
		$('#special-offer-up').hide(); 
	} else {
	
		$('#special-offer-up').addClass('disabled');
		var liHeight = $('#special-offer-show ul li').outerHeight('true');
		var liHeightVisible = liHeight * liVisible;
		var ulHeight = $('#special-offer-show ul').outerHeight('true');
		var slideCount = Math.ceil(ulHeight/liHeightVisible);
		
		slideNo = 0;
		var slideAnim=0;

		$('#wrapper.home .row_1').find('#special-offer-down, #special-offer-up').click(function(){
			var button = $(this);
			
			if ( button.is('#special-offer-up'))
			{
				if ((slideNo > 0) && (slideNo <= slideCount)) { 
					slideNo--; 
					slideAnim = -(liHeightVisible*slideNo); 
					$(this).next().removeClass('disabled'); 
				}
			} else if ( button.is('#special-offer-down')) {
				if (slideNo < (slideCount-1)) { 
					slideNo++; 
					slideAnim = -(liHeightVisible*slideNo);
					$(this).prev().removeClass('disabled'); 
				} 
			}
			
			if (slideNo==0) { $('#special-offer-up').addClass('disabled'); } else if (slideNo == (slideCount-1)) { $('#special-offer-down').addClass('disabled'); }
			
			$('#special-offer-show ul').animate({ marginTop: slideAnim }, 400 );
		
		});
	}

	
});

function autoPlay() {
	if ( $('#special-offer-show li.on').next('li').length > 0 ) {
		$('#special-offer-show li.on').next('li').addClass('on').siblings().removeClass('on');
		if( $('#special-offer-show li').length > 3 && ( $('#special-offer-show li.on').index() )%3 == 0 ) { 
			$('#special-offer-down').click(); 
		}
	} else {
		$('#special-offer-show li:eq(0)').addClass('on').siblings().removeClass('on');
		if( $('#special-offer-show li').length > 3 ) { 
			$('#special-offer-up').addClass('disabled');
			$('#special-offer-down').removeClass('disabled');
			slideNo = 0;
			$('#special-offer-show ul').animate({ marginTop: 0 }, 500 );
		}
	}
}


//BOX BEST BUY HOME
$(document).ready(function(){

	var liCount = $('#boxBestBuy .wrapper ul li').length;
	var liVisible = 3;
	
	$('#boxBestBuy .wrapper ul li:nth-child('+liVisible+'n+1)').addClass('first-in-slide');
	if (liCount <= liVisible) 
	{ 
		$('#boxBestBuy .left').hide(); 
		$('#boxBestBuy .right').hide(); 
	} 
	else
	{ 
		$('#boxBestBuy .left').addClass('disabled'); 
		var liWidth = $('#boxBestBuy .wrapper ul li').outerWidth('true');
		var ulWidth = liCount * liWidth;
		$('#boxBestBuy .wrapper ul').css('width', ulWidth);
	
	
		var liWidthVisible = liWidth * liVisible;
		var slideCount = Math.ceil(ulWidth/liWidthVisible);
		
		var slideCurr = 0;
		var slideAnim = 0;

		$('#boxBestBuy').find('.left, .right').click(function(){
		
			var button = $(this);
			
			if ( button.is('.left') )
			{
				if ((slideCurr > 0) && (slideCurr <= slideCount)) 
				{ 
					slideCurr--; 
					slideAnim = -(liWidthVisible*slideCurr); 
					$(this).next().removeClass('disabled'); 
				} 
			}
			else if ( button.is('.right') )
			{
				if (slideCurr < (slideCount-1)) 
				{ 
					slideCurr++; 
					slideAnim = -(liWidthVisible*slideCurr);
					$(this).prev().removeClass('disabled'); 
				} 
			}
			if (slideCurr==0) { $('#boxBestBuy .left').addClass('disabled'); } else if (slideCurr == (slideCount-1)) { $('#boxBestBuy .right').addClass('disabled'); }
		
			$('#boxBestBuy .wrapper ul').animate({ marginLeft: slideAnim }, 500 );
	});
}
	
});


//PROJECTS home

$(document).ready(function()
{
		var slideCount = $('.project-slides .project-slide').length;
		var slideCurr = 1; //postavljamo vrijednost trenutnog elementa na 1
		$('#projects-nav .text').text(slideCurr + '/' + slideCount);
		var slideWidth = $('.project-slides .project-slide').outerWidth('true');
		var slidesWidth = slideCount * slideWidth;
		$('.project-slides').css('width', slidesWidth);

		if (slideCount <= slideCurr) 
		{ 
			$('#projects-nav').hide(); 
		} 
		else
		{ 
			$('#projects-nav').find('.left, .right').click(function(){
			
				var button = $(this);
				
				if ( button.is('.left') && (slideCurr <= slideCount) && (slideCurr > 1))
				{
					slideCurr--;
					slideAnim = -(slideWidth*(slideCurr-1));
				}
				else if ( button.is('.right') && (slideCurr < slideCount) )
				{
					slideAnim = -(slideWidth*slideCurr);
					slideCurr++;
				}

				$('#projects-nav .text').text((slideCurr) + '/' + slideCount);
				$('.project-slides').animate({ marginLeft: slideAnim }, 400 );
		
			});
		}
});


//HEADER SLIDESHOW
$(window).load(function(){
	$("#header_slideshow").cycle({
		timeout:3000
	});
});



//PAGINATION ellipsis
$(document).ready(function() {
	$('ul.pagination').each(function() {
		$(this).find('a:not([href]):not(.active)').parent().addClass('ellipsis');
	});
});

//HOME SPECIAL OFFER BOX
$(document).ready(function(){
	$('.box-special-offer div.detail:first, .box-special-offer div.thumb_wrapper table td:first').addClass('active');
	$('.box-special-offer div.thumb_wrapper table td').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	$('.box-special-offer div.thumb_wrapper table td a').live('click', function(e) {
		e.preventDefault();
		var link = $(this).attr('href');
		$('.box-special-offer div.thumb_wrapper table td').removeClass('active');
		$(this).parents('td').addClass('active');
		$('.box-special-offer div.detail a.imgWrapper[href=' + link + ']').parent().addClass('active').siblings().removeClass('active');
	});
});

// CONTROL BOX
$(document).ready(function()
{
 	$(".controlBox div ul li.rel-title").each(function() {
		var box=$(this);
		$(this).click(function() 
		{
			var box=$(this);
			if ($(this).children("ul.active").length > 0) { $(box).children("ul").removeClass('active'); }
			else { $(box).children("ul").addClass('active'); }
		});
		});
		
		$(".controlBox div ul li.rel-title").mouseleave(function() { $(this).children('ul').removeClass('active'); });
	
});

//SEARCH
$(document).ready(function(){
    $("#searchForm select").each(function()
		{
      $(this).hide().after('<span class="sel-replaced'+(($(this).is(".off"))?" off":"")+' '+$(this).attr("id")+'">'+$(this).find("option:selected").text()+'</span>');
			
			var spanText = new Array();
			if ($(this).hasClass("cities")) 
			{ 
				$(this).find("option:selected").each(function(i)
					{ spanText[i] = $(this).text(); });
				if(spanText.length!=0)
				{                      
					if(spanText.join(",").length<25)
						{ $(this).next(".sel-replaced").text(spanText.join(",")); } 
					else 
						{ $(this).next(".sel-replaced").text(spanText.join(",").substr(0,25)+"..."); }
				
				} 
			}
    });

    $("#searchForm .single .sel-replaced").mightySelect("advanced","");
    $("#searchForm .dependable .sel-replaced").mightySelect("advanced","dependable");
    
    /* Checkbox */
    $("#searchForm .chk").click(function(){
        $(this).parent("label").siblings("label").find(".chk").removeAttr("checked");
        if($("#searchForm .chk:checked").size() == 0) $(this).attr("checked", "checked");
    });
		
		var bkgID = $("#searchForm li.ID span.rpl-bkgID input:text")
		if ( bkgID.val() == "" ) { bkgID.val( bkgID.prev("label").text() )}
 		 
		 $(bkgID).focus(function()
		 {
        if ( $(this).val() == $(this).prev("label").text() )
				{ $(this).val(""); }
    });
		
		$(bkgID).blur(function()
		 {
        if ( $(this).val() == "" )
				{ $(this).val( $(this).prev("label").text() ) }
    }); 
		
     
    $("#searchForm").submit(function(){
        $(this).find("input:text").each(function(){
            if($(this).val()==""){ $(this).attr("disabled","disabled"); }
        });
        $(this).find("select").each(function(){
            if($(this).val()==""||$(this).val()==null){ $(this).attr("disabled","disabled"); }
        });
				if ( bkgID.val() == $(bkgID).prev("label").text() ) { bkgID.val(""); }
    });
		
});

//GOOGLE MAP
var map;
$(document).ready(function() {

    if ( $('#google-map').html()!=null ) {
		var markerCord = $('#gmap-wrapper').attr("rel").split("|");
		map = new google.maps.Map(document.getElementById("google-map"), {
			zoom: 14,
			mapTypeControlOptions: {
			  mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID ]
			},
			navigationControlOptions: {style: google.maps.NavigationControlStyle.DEFAULT},
			center: new google.maps.LatLng( markerCord[0], markerCord[1] ),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		});
		var marker = new google.maps.Marker({
			position: new google.maps.LatLng( markerCord[0], markerCord[1] ),
			map: map
		});
	}

    if ( $('.mapBoxWrapper').html()!=null ) {

		var markerCord = $(".mapBoxWrapper").attr("rel").split("|");
        var mapOffset = $(".mapBoxWrapper").offset();				
		var mapOffsetRight = $(document).width() - ( mapOffset.left + $('.mapBoxWrapper').outerWidth() );
		
        $("body").append('<div class="mapBox" style="top:'+mapOffset.top+'px; right:'+mapOffsetRight+'px;"><div id="gMap"></div><a class="button" title="'+phrasebook.enlarge_map+'"></a></div>');

        $(window).resize(function(){
            mapOffset = $(".mapBoxWrapper").offset();
			mapOffsetRight = $(document).width() - ( mapOffset.left + $('.mapBoxWrapper').outerWidth() );
            $(".mapBox").css({right: mapOffsetRight, top: mapOffset.top});
        });
		
		map = new google.maps.Map(document.getElementById("gMap"), {
			zoom: 14,
			mapTypeControlOptions: {
				mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID ]
			},
			navigationControlOptions: {style: google.maps.NavigationControlStyle.DEFAULT},
			center: new google.maps.LatLng( markerCord[0], markerCord[1] ),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		});
		var marker = new google.maps.Marker({
			position: new google.maps.LatLng( markerCord[0], markerCord[1] ),
			map: map
		});
		
        $(".mapBox a.button").toggle(function(){
            var el = $(this);
            $(".mapBox").animate({width: "637px", height: "403px" },function(){
                el.addClass("close");
				google.maps.event.trigger(map, 'resize');
				map.setCenter(marker.position);                
                el.attr('title', phrasebook.reduce_map);
            });
        },function(){
            var el = $(this);
            $(".mapBox").animate({width: "245px", height: "261px" }, function(){
                el.removeClass("close");
				google.maps.event.trigger(map, 'resize');
				map.setCenter(marker.position);
                el.attr('title', phrasebook.enlarge_map);
            });
        });

	}
});

//QUERY INFO POPUP
$(document).ready(function() {
    $(".icon-info").click(function(){
        if($(this).attr("rel")==$(".info-popup-wrapper").attr("rel")){
            $(".info-popup-wrapper").remove();
        } else {
            $(".info-popup-wrapper").remove();
            var offset = $(this).offset();
            $("body").append('<div rel="'+$(this).attr("rel")+'" class="info-popup-wrapper">'+$(this).next(".info-popup").html()+'</div>')
            $(".info-popup-wrapper").css({left: offset.left, top: offset.top+21}).show();
            
        }
    });
});

//QUERY POPUP
$(document).ready(function() {
    $('.agent .button a:first').click(function(event){
	    var re_realEstates_id = $(this).attr("rel");
      $.get(phrasebook.URL_ROOT+"/index.php?page=queryPopup&re_realEstates_id="+re_realEstates_id, function(data){
          $("body").append(data);          
          var pos = $(".detail-box").offset();
          $("#queryPopup").css({ top: pos.top, left: pos.left+122 }).show();
					$('html, body').animate({scrollTop:pos.top-40}, 'slow');
          
          $(window).resize(function(){
              var pos = $("#column-1").position();
              $("#queryPopup").css({ top: pos.top, left: pos.left }).show();
          });          
          
          $("#queryPopup .close").click(function(){
              $("#queryPopup").remove();
          });
          
          $(document).bind('click', function(e){
              var $clicked = $(e.target);
              if (!($clicked.is('#queryPopup') || $clicked.parents().is('#queryPopup'))) {
                $("#queryPopup").remove();
                $(document).unbind('click');
              }
          });  
          var realEstateAction = $("#queryPopup form").attr("action");
          $("#queryPopup button[type=submit]").click(function(){
              $("#queryPopup input").removeClass("error");
              switch ($("#queryPopup .radio:checked").val()){
                  case "email":
                    if( $("#quaryEmail").val()=="" ){ $("#quaryEmail").addClass("error"); }                   
                    break;
                  case "phone":
                    if( $("#quaryPhone").val()=="" ){ $("#quaryPhone").addClass("error"); }
                    break;              
              }
              if($("#queryPopup .error").length>0){ return false; }
              else {
                  $.get(realEstateAction, { re_realEstates_id:$("#re_realEstates_id").val(),re_realEstates_title:$("#re_realEstates_title").val(),contact_method:"email",quaryName:$("#quaryName").val(),quaryPhone:$("#quaryPhone").val(),quaryEmail:$("#quaryEmail").val(),quaryMessage:$("#quaryMessage").val() },function(data){
                    $("#queryPopup fieldset.left").remove();
                    $("#queryPopup fieldset label").remove();
                    $("#queryPopup fieldset textarea").remove();
                    $("#queryPopup button[type=submit]").remove();
                    $("#queryPopup blockquote").after("<p class='note'>"+data+"</p>");
                    
                	});
              }
              return false;
          });
      });
	});
});

//QUERY FORM CHECK
$(document).ready(function() {
    $("#query-form").submit(function(){
        $(this).find(".error").removeClass("error");
        $(this).find("label:has(em)").next().each(function(){
            if($(this).val()==""){
                $(this).addClass("error");
            }
        });
        if($(this).find(".error").length>0){ $(this).find(".error:first").focus(); return false; }
    });
});

//OPEN VIDEO
$(document).ready(function() {
    $(".files .video a").click(function(){
        $("select").css("visibility","hidden");
        $("body").append('<div id="video-popup-overlay" title="zatvori"></div><div id="video-popup"><div id="flashVideoPopup"></div><img class="close" src="'+phrasebook.URL_ROOT+'/images/lightbox-btn-close.gif" alt="zatvori" title="zatvori" /></div>');
        
        var overlayEl = $("#video-popup-overlay");
        var popupEl = $("#video-popup");
        var closeButton = popupEl.find(".close");          
        var left = ($(window).width() - popupEl.width())/2;
        var top = $(window).scrollTop()+50;
        
        $(window).resize(function(){ position_popup(overlayEl,popupEl); });
        overlayEl.click(function(){ close_popup(overlayEl,popupEl); });
        closeButton.click(function(){ close_popup(overlayEl,popupEl); });

        var link=$(this).attr("rel");
        var timestamp = Number(new Date());
        var flashvars = {file: link,controlbar: "over",autostart: "true"};
        var params = {allowscriptaccess: "always",allowfullscreen: "true"};
        var attributes = {id: "mpl",name: "mpl"};
        swfobject.embedSWF(phrasebook.URL_ROOT+'/player.swf?'+timestamp, "flashVideoPopup", "480", "384", "9","", flashvars, params, attributes);
        
        overlayEl.css({ height:$(document).height(), width:$(window).width(), opacity: "0.8" }).show();
        if((top+parseFloat(popupEl.height()))>overlayEl.height()){ overlayEl.height((top+parseFloat(popupEl.height()))+30); }
        popupEl.css({ left: left, top: top }).fadeIn("slow");
               
    });
    
    function position_popup(overlayEl,popupEl){
        overlayEl.hide().css({ height:$(document).height(), width:$(document).width(), opacity: "0.8" }).show();
        var left = ($(window).width() - popupEl.width())/2;
        var top = $(window).scrollTop()+50;
        popupEl.css({ left: left, top: top });
    }
    
    function close_popup(overlayEl,popupEl){
        playerPopupVideo = null;
        swfobject.removeSWF("mpl");
       
        popupEl.fadeOut("slow",function(){
            popupEl.remove();
        });
        overlayEl.fadeOut("slow",function(){
            $("select").css("visibility","visible");        
            overlayEl.remove();
        });
        $(window).unbind("resize");
    }

});


//************************ Share toolbar ***/
$(function() {
  $("body").append('<div id="dimedia-toolbar"><div class="bottom-bkg"><div class="middle-bkg"><ul><li><a href="http://www.facebook.com/share.php?u=|&t=" rel="facebook" title="facebook"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon1.gif" alt="facebook" /></a></li><li><a href="http://twitter.com/home?status=|%20-%20" rel="twitter" title="twitter"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon2.gif" alt="twitter" /></a></li><li><a href="http://digg.com/submit?phase=2&url=|&title=" rel="digg" title="digg"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon3.gif" alt="digg" /></a></li><li><a href="http://delicious.com/post?url=|&title=" rel="delicious" title="delicious"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon4.gif" alt="delicious" /></a></li><li><a href="http://www.myspace.com/Modules/PostTo/Pages/?u=|&t=" rel="myspace" title="myspace"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon5.gif" alt="myspace" /></a></li><li><a href="http://www.stumbleupon.com/submit?url=|&title=" rel="stumbleupon" title="stumbleupon"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon6.gif" alt="stumbleupon" /></a></li><li><a href="http://www.google.com/bookmarks/mark?op=edit&bkmk=|&title=" rel="google" title="google bookmarks"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon7.gif" alt="google bookmarks" /></a></li><li><a href="http://bookmarks.yahoo.com/toolbar/savebm?opener=bm&ei=UTF-8&u=|&t=" rel="yahoo" title="yahoo bookmarks"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon8.gif" alt="yahoo bookmarks" /></a></li><li><a href="http://www.linkedin.com/shareArticle?mini=true&url=|&title=" rel="linkedin" title="linkedin"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon9.gif" alt="linkedin" /></a></li><li><a href="https://favorites.live.com/quickadd.aspx?marklet=1&url=|&title=" rel="live" title="live"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon10.gif" alt="live" /></a></li><li><a href="http://technorati.com/faves?add=|" rel="technorati" title="technorati"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon11.gif" alt="technorati" /></a></li><li><a rel="mail" title="e-mail"><img src="'+phrasebook.URL_ROOT+'/images/toolbar/dimedia-toolbar-icon12.gif" alt="e-mail" /></a></li></ul></div></div></div>');

  $("#dimedia-toolbar a, .innerControls li.share a").click(function(){
      if(!($(this).attr("rel")==null||$(this).attr("rel")=="")){
          var pageTitle = encodeURI(document.title.replace(/š/g,"s").replace(/ð/g,"d").replace(/è/g,"c").replace(/æ/g,"c").replace(/ž/g,"z").replace(/Š/g,"S").replace(/Ð/g,"D").replace(/È/g,"C").replace(/Æ/g,"C").replace(/Ž/g,"Z"));
          var pageLink = encodeURI(window.location)+( ( window.location.toString().indexOf('?') < 0 ) ? '?l='+phrasebook.LANGUAGE : '&l='+phrasebook.LANGUAGE );
          switch ($(this).attr("rel")){
              case "mail":
                  window.location = "mailto:?subject="+pageTitle+"&body="+pageLink;
                  $(".dimedia-toolbar-button").click();
                  break;
              case "twitter":
                  var link = $(this).attr("href").split("|");
                  window.open(link[0]+pageTitle+link[1]+pageLink,"_blank");
                  $(".dimedia-toolbar-button").click();
                  return false;
                  break;
              case "technorati":
                  var link = $(this).attr("href").split("|");
                  window.open(link[0]+pageLink,"_blank");                  
                  $(".dimedia-toolbar-button").click();
                  return false;
                  break;
              default:
                  var link = $(this).attr("href").split("|");
                  window.open(link[0]+pageLink+link[1]+pageTitle,"_blank");
                  $(".dimedia-toolbar-button").click();
                  return false;
                  break;
          }
      }
  });
  
  $(".dimedia-toolbar-button").toggle(function(){
      var dimediaToolbarPosition = $(".dimedia-toolbar-button").offset();
      var dimediaToolbarPositionTop = dimediaToolbarPosition.top-$("#dimedia-toolbar").height()-5;
      var dimediaToolbarPositionLeft = dimediaToolbarPosition.left;
      $("#dimedia-toolbar").css({top:dimediaToolbarPositionTop,left:dimediaToolbarPositionLeft});
      
      $(this).addClass("on");
      if ($.browser.msie && $.browser.version==6) {
        $("#dimedia-toolbar").css({marginTop:"-20px"}).show();
      } else {
        $("#dimedia-toolbar").css("display","block").animate({marginTop:"-20px",opacity:"1"});
      }
  },function(){
      if ($.browser.msie && $.browser.version==6) {
        $("#dimedia-toolbar").hide();
      } else {
        $("#dimedia-toolbar").animate({marginTop:"0px",opacity:"0"},function(){
            $(this).css("display","none");
            $(".dimedia-toolbar-button").removeClass("on");    
        });
      }
  });
});

