//FONT SIZE
$(document).ready(function(){
	var fontCookie = $.cookie('font_size');
	if ( fontCookie == 'val1' ) { $('body').css('fontSize', '1em'); }
	if ( fontCookie == 'val2' ) { $('body').css('fontSize', '1.2em'); }
	if ( fontCookie == 'val3' ) { $('body').css('fontSize', '1.4em'); }
	
	$('#font a').click(function(e){
		e.preventDefault();
		if ( $(this).hasClass('font_reset') ) { $('body').css('fontSize', '1em'); $.cookie('font_size', 'val1' ); }
		if ( $(this).hasClass('font_large') ) { $('body').css('fontSize', '1.2em'); $.cookie('font_size', 'val2' ); }
		if ( $(this).hasClass('font_xlarge') ) { $('body').css('fontSize', '1.4em'); $.cookie('font_size', 'val3' ); }
		resizeCells();
	});
});

//LIGHTBOX
$(document).ready(function() {
    $(".lightbox").lightBox();
    $(".lightboxPhoto").lightBox();
    $(".lightboxGround").lightBox();
    $(".lightboxModels").lightBox();
    $(".lightboxPhases").lightBox();
});

//REAL ESTATE DETAIL TABS & GALLERY
$(document).ready(function() {
	var wTabs = 32;
	$('#detail_box ul.tabs li').each(function() {
		wTabs += $(this).width();
	});
	
	if ( $('#detail_box ul.tabs li').length == 0 ) { var wTabs = 19; }
	$('#detail_box .viewsNo').css('left', wTabs );
	
	$('#detail_box ul.tabs li:last').addClass('last');

	$('.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+')').addClass('active').siblings().removeClass('active');
		$(this).addClass('active').siblings('li').removeClass('active');
	});
	
	$('.multimedia_box > div').each(function(){
		
		var box = $(this);
		
		$(box).find('a.mainImgWrapper').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('.mainImgWrapper img:not(.patch)');
			$(mainImg).attr('src', rel);
			$(mainImg).parent().attr({href: href, rel: count});
		});
		
		var containerHeight = $(box).find('.container').height();
		var slideCount = $(box).find('.container ul').length;
		var currSlide = 1;

		if (slideCount > 1) {
			$(box).find('.nav .txt').text(currSlide+'/'+slideCount);
			$(box).find('.nav .up, .nav .down').click(function() {

				if ( $(this).is('.up') ) {
					if (currSlide <= 1) { return false; }
					slideAnim = '+='+containerHeight;
					currSlide--;
				}
					
				if ( $(this).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);
				});
			});
		}
		else { $(box).find('.nav').hide(); }
	});
});


//MAIN NAVIGATION
$(document).ready(function(){
	$('#main_nav li.dropdown .shadow, #flgqWrapper li .shadow').css('opacity', 0);
	$('#main_nav li.dropdown .shadow.projects').width(236);
	$('#main_nav li.dropdown .shadow:not(.projects)').each(function(){
		$(this).width( 151 * $(this).find('ul').length );
	});
	$('#main_nav li.dropdown, #flgqWrapper li').hover(function(){
		$(this).find('.shadow').stop(true, true).fadeTo(400, 1);
	}, function(){
		$(this).find('.shadow').stop(true, true).fadeTo(300, 0, function(){ $(this).hide(); });
	});
});


//TABLE CLASSES
$(document).ready(function(){
	$('.table-type-2').each(function(){
		$(this).find('td:last').addClass('last');
	});
	resizeCells();
/*
	$('table tr:nth-child(odd)').addClass('odd');
	$('table tr:nth-child(even)').addClass('even');
	$('table tr td:last-child').addClass('last');
	$('table tr:last').addClass('last');
*/
});

function resizeCells() {
	$('.table-type-1 tr').each(function(){
		$(this).find('.cell').height('auto');
		var maxH = 0;
		$(this).find('.cell').each(function(){
			var currH =  $(this).height();
			if (currH > maxH) { maxH = currH; }
		});
		$(this).find('.cell').height(maxH);
	});
}

//PAGINATION
$(document).ready(function() {
	$('ul.pagination').each(function() {
		$(this).find('a:not([href]):not(.active)').addClass('ellipsis');
	});
	if ( $('#main_content').is('.noLeft') ) {
		var pagPad = ( 735 - $('#main_content.noLeft ul.pagination.bottom').width() )/2;
	} else if ( $('#main_content').is('.yesLeft') ) {
		var pagPad = ( 519 - $('#main_content.yesLeft ul.pagination.bottom').width() )/2;
	} else { var pagPad = 0; }
	$('ul.pagination.bottom').css({
		paddingLeft: pagPad,
		paddingRight: pagPad
	});
	if ( $('#re_list, #pr_list').length > 0 && $('.controlsWrapper.bottom ul.pagination').length == 0 ) { $('.controlsWrapper.bottom').remove(); }
});

//SEARCH
$(document).ready(function(){
    $("#searchForm select").not("[multiple]").each(function(){
        $(this).hide().after('<span class="sel-replaced'+(($(this).is(".off"))?" off":"")+' '+$(this).attr("id")+'"><span>'+$(this).find("option:selected").text()+'</span></span>');
    });
    $("#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");
    });
     
    $("#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"); }
        });
    });
    
});

//ACCORDION SIDEBAR
$(document).ready(function(){
	$('.accordion_box').each(function(){
		$(this).find('.item:eq(0)').addClass('first');
		$(this).find('.item:last').addClass('active');
	});
	$('.accordion_box h2').live('click', function() {
		if ( !($(this).closest('.item').is('.active')) ) {
			$(this).closest('.accordion_box').find('.item.active .content').slideUp(200, function(){ 
				$(this).closest('.item').removeClass('active'); 
			});
			$(this).siblings('.content').slideDown(200, function(){ 
				$(this).closest('.item').addClass('active'); 
			});
		}
		else {
			$(this).siblings('.content').slideUp(200, function(){ 
				$(this).closest('.item').removeClass('active'); 
			});		
		}
	});
});

//TOOLTIPS
$(document).ready(function(){
	$('#sub_header .ctrls li').hover(function(){
		if ( !($(this).children('a').hasClass('on')) ) {
			$(this).find('.cloud').css('margin-left', 8 -( $(this).find('.cloud').width() / 2 ) );
			$(this).find('.cloud').show();
		}
	}, function(){
		$(this).find('.cloud').hide();
	});
});

//CYCLE
$(document).ready(function(){
	if ( $('#home_slideshow .item').length < 2 ) { $('#home_slideshow_next').remove(); }
	if ( $('#txt_slides .item').length < 2 ) { $('#txt_slides_next').remove(); }
});
$(window).load(function() {
	$('#home_slideshow .item .content').show();
    $('#home_slideshow').cycle({
		fx: 'fade',
		timeout: 4000,
		pager: '#home_slideshow_nav',
		next: '#home_slideshow_next',
		pause: 1
	});
    $('#txt_slides').cycle({
		fx: 'fade',
		timeout: 4000,
		pager: '#txt_slides_nav',
		next: '#txt_slides_next',
		pause: 1
	});
	$('#txt_slides').width( 767 - $('#txt_slides_nav').width() - 29 - 10 );
});

//IE BG TOP
$(document).ready(function(){
	if ($.browser.msie) {
		$('#main_content .page_header, #sidebarLeft .nav_box').prepend('<div class="ieTop"></div>');
	}
});

//CONTROL BOX DROPDOWN
$(document).ready(function() {
 	$('.controlsWrapper .dropdown 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'); }
		});
		});
		
		$('.controlsWrapper .dropdown ul li.rel-title').mouseleave(function() { $(this).children('ul').removeClass('active'); });
	
});

//LIST TABLE IMG SLIDER
$(document).ready(function(){
	$('table.table-type-1 .cell').each(function(){
		var totalNum = $(this).find('.img_list span').length;
		$(this).find('.img_list span:eq(0)').addClass('active');
		if ( totalNum < 2 ) {
			$(this).find('.image_nav ul').remove();
		} else {
			$(this).find('.image_nav .count').html( '<span class="curr">1</span>/' + totalNum );
		}
	});
	$('.image_nav .prev, .image_nav .next').live('click', function(){
		var theImg = $(this).closest('.imgSliderWrapper').find('.imgWrapper img:not(.patch)');
		//var theImgAlt = $(theImg).attr('alt');
		var theImgAlt = '';
		var theImgParent = $(theImg).closest('.imgWrapper');
		$(theImg).remove();
		var spanCurr = $(this).closest('.imgSliderWrapper').find('.img_list span.active');
		var spanFirst = $(this).closest('.imgSliderWrapper').find('.img_list span:eq(0)');
		var spanLast = $(this).closest('.imgSliderWrapper').find('.img_list span:last');

		
		if ( $(this).is('.next') ) {
			var currNum = $(spanCurr).removeClass('active').prevAll().length + 2;
			var imgSrc = $(spanCurr).next().addClass('active').attr('rel');
			if ( $(spanCurr).next().length == 0 ) {
				var imgSrc = $(spanFirst).addClass('active').attr('rel');;
				var currNum = 1;
			}
		}
		
		if ( $(this).is('.prev') ) {
			var currNum = $(spanCurr).removeClass('active').prevAll().length;
			var imgSrc = $(spanCurr).prev().addClass('active').attr('rel');
			if ( $(spanCurr).prev().length == 0 ) {
				var imgSrc = $(spanLast).addClass('active').attr('rel');;
				var currNum = $(spanCurr).nextAll().length + 1;
			}
		}
		
		$(theImgParent).append('<img alt="' + theImgAlt + '" src="' + imgSrc + '" />');
		//$(theImgParent).append('<img class="photo" style="display:none;" alt="' + theImgAlt + '" src="' + imgSrc + '" />');
		//$(theImgParent).find('.photo').fadeTo(100, 1);
		$(this).closest('.imgSliderWrapper').find('span.curr').text(currNum);
	});
});

//LIST01 (NEWS) ALIGNMENT
$(document).ready(function() {
	$('ul.list01 li.item').each(function(){
		if ( $(this).find('a.imgWrapper').length == 0 ) { $(this).addClass('noImg'); }
	});
});


//LOCATION-DESCRIPTION SWITCH
$(document).ready(function(){
	if ( $(".switch-top a").length > 0 ) {
		$(".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;
		});
	}
	else { $(".switch-top").remove(); }
});

//CLEAR-DEFAULT TEXT
$(document).ready(function() {
	$('input.clear-default').each(function() {
		var defaultTitle = $(this).attr('title');
		if ($(this).attr('value') == defaultTitle) {
			$(this).css('color', '#d5c0c0');
		}
		if ($(this).attr('value') == '') {
			$(this).attr('value', defaultTitle).css('color', '#d5c0c0');
		}
		$(this).focus(function() {
			if ($(this).attr('value') == defaultTitle) {
				$(this).attr('value', '').css('color', '#ffffff');
			}
		});
		$(this).blur(function() {
			if ($(this).attr('value') == '') {
				$(this).attr('value', defaultTitle).css('color', '#d5c0c0');
			}
		});
	});
	$('input.clear-default').closest('form').submit(function() {
		$(this).find('input[type=text][title]').each(function() {
			var defaultTitle = $(this).attr('title');
			if ($(this).attr('value') == defaultTitle) {
				$(this).attr('value', '');
			}
		});
	});
});

//FILE INPUT
function fileValueSwitch() {
    if($(".fileWrap").html()!=null){
        $(".fileWrap").mousemove(function(e){
			var pos = $(".fileWrap").offset();
			$("#fileInput").css({
				top: (e.pageY-pos.top-$('#fileInput').height()+10) +"px",
				left: (e.pageX-pos.left-$('#fileInput').width()+55) + "px"
			});
        });
        var so = document.getElementById("fileInput");
        so.onchange = so.onmouseout = function(){
        	var inputValue = this.value;
        	$("#dummyInput").val(inputValue);
        }
    }
}

$(document).ready(function(){
  fileValueSwitch();  
  $("#clearFile").click(function(){
	  $("#dummyInput").val("");
	  var tempHtml = $(".fileWrap").html();
	  $("#fileInput").remove();
	  $(".fileWrap").html(tempHtml);
	  fileValueSwitch();     
  });  
});

//GOOGLE MAP
$(document).ready(function() {
    if ($("#google-map").html()!=null){
        DGoogleMap2.setOption( 'zoom', 14 );
        DGoogleMap2.setOption( 'center', new GLatLng(44.5, 16.2) );
        DGoogleMap2.mapDefaultUI.zoom.scrollwheel=false;
        
        DGoogleMap2.mapDefaultUI.controls.largemapcontrol3d=false;
        DGoogleMap2.mapDefaultUI.controls.smallzoomcontrol3d=true;
        
        var s = DGoogleMap2.displayMap("#google-map");
        DGoogleMap2.displayMarkers();
        DGoogleMap2.fitMapToMarkers();
    }
    
    if ($(".mapBoxWrapper").html()!=null){
        
        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">'+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});
        });
        
        var markerCord = $(".mapBoxWrapper").attr("rel").split("|");
        DGoogleMap2.mapDefaultUI.zoom.scrollwheel=false;
        DGoogleMap2.mapDefaultUI.controls.overviewmapcontrol=false;
        DGoogleMap2.setOption( 'center', new GLatLng(markerCord[0], markerCord[1]) );
        DGoogleMap2.mapObject = new GMap2( $( "#gMap" ).get(0) );
        DGoogleMap2.setCallback( 'displayMap', function() { setTimeout( "$( DGoogleMap2.mapObject.getContainer() ).children().each(function(){if( $(this).attr('id') && !DGoogleMap2.mapContainerFixedChildren[$(this).attr('id')] ) $(this).hide();});", 1000); } );
        DGoogleMap2.displayMap("#gMap");
        DGoogleMap2.setMarker( { 'lat':markerCord[0], 'lng':markerCord[1] }, '', '', { 'image' : phrasebook.URL_ROOT+'/images/marker.png', 'shadow' : phrasebook.URL_ROOT+'/images/marker-shadow.png', 'iconAnchor' : new GPoint( 17, 38 ), 'infoWindowAnchor' : new GPoint( 17, 0 ), 'iconSize' : new GSize( 35, 41 ), 'shadowSize ' : new GSize( 35, 41 ) }, false );        
        $(".mapBox a.button").toggle(function(){
            var el = $(this);
            $(".mapBox").animate({width: "637px", height: "403px" },function(){
                el.addClass("close");
                DGoogleMap2.mapObject.checkResize();
                DGoogleMap2.fitMapToMarkers();
                
                DGoogleMap2.showMapControls();
                
                $(".mapBox .button").text(phrasebook.reduce_map);
            });
        },function(){
            var el = $(this);
            $(".mapBox").animate({width: "245px", height: "261px" }, function(){
                el.removeClass("close");
                DGoogleMap2.mapObject.checkResize();
                DGoogleMap2.fitMapToMarkers();
                
                DGoogleMap2.hideMapControls();
                
                $(".mapBox .button").text(phrasebook.enlarge_map);
            });
        });
        
         
        
    }
});

//POPUP ( CONTACT, FORWARD/SEND TO A FRIEND )
$(document).ready(function() {
	$('a.mail, #sub_header .forward a').live('click', function(e){
		e.preventDefault();
		var _url = $(this).attr('rel');
		$.get(_url, function(data){
			$('body').append('<div id="popupOverlay"></div><div id="popupBox"><div id="popupShadowTop"></div><div id="popupShadowMid"></div><div id="popupShadowBot"></div><div id="popupContent"><div class="close"></div><div class="inner">'+data+'</div></div>');
			$('html, body').animate({scrollTop:0}, 'slow');
			$('#popupBox .close').live('click', function(){
				$('#popupBox, #popupOverlay').remove();
			});
			$('#popupBox form button[type=submit]').live('click', function(e){
				e.preventDefault();
				$.ajax({
					url: _url,
					type: 'POST',
					data: $(this).closest('form').serialize(),
					success: function( data ){
						$('#popupBox .inner').html(data);
					}
				});
			});
		});
	});	
});

//QUERY POPUP
$(document).ready(function() {
    $('.agent a.upit').click(function(event){
		var relArray = $(this).attr('rel').split('|');
	    var id_val = relArray[0];
	    var ag_agents_id = relArray[1];
		var id_name = relArray[2];
      $.get(phrasebook.URL_ROOT+'/index.php?page=queryPopup&ag_agents_id='+ag_agents_id+'&'+id_name+'='+id_val, function(data){
          $('body').append('<div id="popupOverlay"></div><div id="popupBox"><div id="popupShadowTop"></div><div id="popupShadowMid"></div><div id="popupShadowBot"></div><div id="popupContent"><div class="close"></div><div class="inner">'+data+'</div></div>');
		  
		  $('html, body').animate({scrollTop:0}, 'slow');
      
  			$('#popupBox .close, #popupBox .cancel').live('click', function(){
				$('#popupBox, #popupOverlay').remove();
			});
			
          $(document).bind('click', function(e){
              var $clicked = $(e.target);
              if (!($clicked.is('#popupBox') || $clicked.parents().is('#popupBox'))) {
				$('#popupBox, #popupOverlay').remove();
                $(document).unbind('click');
              }
          });  
          var realEstateAction = $("form#queryPopup").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(),pr_projects_id:$("#pr_projects_id").val(),pr_projects_webName:$("#pr_projects_webName").val(),re_realEstates_title:$("#re_realEstates_title").val(),contact_method:"email",quaryName:$("#quaryName").val(),quaryPhone:$("#quaryPhone").val(),quaryEmail:$("#quaryEmail").val(),quaryMessage:$("#quaryMessage").val(),ag_agents_id:$("#ag_agents_id").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 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 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; }
    });
});

//JOB FORM ERROR SCROLL
$(document).ready(function() {
	if ( $('#jobForm .error').length > 0 ) {
		var pos = $('#jobForm .error:first').offset();
		$('html, body').animate({scrollTop:pos.top-65}, 'slow');
	}
});

//************************ 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").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);
          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, #sub_header .ctrls li.share a").toggle(function(){
      var dimediaToolbarPosition = $(this).offset();
      var dimediaToolbarPositionTop = dimediaToolbarPosition.top-$("#dimedia-toolbar").height()-4;
      var dimediaToolbarPositionLeft = dimediaToolbarPosition.left-22;
      $("#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, #sub_header .ctrls li.share a").removeClass("on");    
        });
      }
  });
});

//OPEN NEW WINDOW
function openNewWindow (adresa, ime, w, h, sc)
{
	var prozor = window.open(adresa, ime, "toolbar=no,height="+h+",width="+w+",location=no,directories=no,status=no,menubar=no,scrollbars="+sc+",resizable=yes");
	prozor.focus();
}

