
// deschidem imaginile care erau inainte deschise de lightbox
//-------------------------------------------------------------------
$(document).ready(function(){
	$("a[rel^='lightbox']").each(function() {	//deschide galerie multimedia
		$(this).addClass("zoom_img_editor_link");
	});
});



// zoom imagini din content (introduse cu editorul) cu thickbox
// ==========================================

$(document).ready(function(){
	$(".zoom_img_editor").each(function() {
		$(this).wrap("<a class='zoom_img_editor_link' href='"+$(this).attr('name')+"' title='"+$(this).attr('alt')+"' rel='galerie_content'></a>");
		$(this).parent().append("<span>" + $(this).attr('alt') + "</span>");
	});
	
	$.repairLink2Anchor();
	
});


// JW Player
//-------------------------------------------------------------------
$(document).ready(function(){
	$(".jwplayer").each(function() {
		var jw_file = $(this).attr('title');
			if (jw_file.match("xupload")) {
				jw_file = "../" + jw_file
				}
		var jw_cover = $(this).attr('name');
		var jw_type = $(this).attr('lang');
			if (jw_type == null) {
				jw_type = 'true'; //true = video , false = audio
				};
		var jw_width = $(this).attr('width');
			if (jw_width == "") {
				jw_width = '470';
				};
		var jw_height = $(this).attr('height');
			if (jw_height == "") {
				jw_height = '320';
				};
			if (jw_type == 'false') {
				jw_height = '24';
				};
		var jw_autostart = $(this).attr('rel');
			if (jw_autostart == null) {
				jw_autostart = 'false';
				};	
				
		var jw_random_id=Math.floor(Math.random()*111111)
		
		
		var jw_player = " <div class='jwplayer_container'> "+
						" <div  id='"+jw_random_id+"'> "+
						" <SCRIPT type=text/javascript> " +
						" var flashvars = { " +
						"  file: '"+jw_file+"', " +
						"  image: '"+jw_cover+"', " +
						"  autostart: '"+jw_autostart+"', " +
						//"  skin: 'http://81.181.224.182/__portal/a/res_js/jv_player/modieus.zip', " +
						"  screencolor: 'e5e5e5' " +
						" }; " +
						" var params = {  " +
						"  base: '.', " +
						"  quality: 'best', " +
						"  bgcolor: '#e5e5e5', " +
						"  allowfullscreen: 'true', " +
						"  wmode: 'transparent' " +
						" };                 " +
						" var attributes = { " +
						"  id: '"+jw_random_id+"' " +
						" }; " +
						" swfobject.embedSWF('../res_js/jv_player/player.swf', '"+jw_random_id+"', '"+jw_width+"', '"+jw_height+"', '9.0.115.0', false, flashvars, params, attributes); " +
						" </SCRIPT> " +
						"</div>" +
						"</div>";	
			
		$(this).html(jw_player);
	
	
	});
});



	
$(document).ready(function() { 
	
	//deschidem linkurile catre imaginile din content cu ZOOM
	//------------------------------------------------------
	$("a img.imgzoom").parent().addClass("imgzoom_a");
	$('.imgzoom_a').live("click", function () {
		var t = this.title || this.name || null;
		var a = this.href || this.alt;
		var g = this.rel || false;
		tb_show(t,a,g);
		this.blur();
		return false;
	});
	//------------------------------------------------------/
	
	
	$(document.createElement('div')).css({'clear': 'both'}).insertAfter(".left_site_container");
	
	// round corners
	//$('.foto_mare_sec').corner("3px");
	//$('.foto_mare_art').corner("3px");
	
	// color bg la option selected
	$("select option:selected").css({backgroundColor: '#e1e1e1'});
	
	// erori , mesaje server - animatie
	$('.listare_eroare, .listare_mesaj').css({'opacity':0,'display':'block'});
	setTimeout(function() { $('.listare_eroare, .listare_mesaj').animate({opacity: 1}, "slow");}, 50); 
	
	

}); 


	
 




// Increase Font Size
//-------------------------------------------------------------------
$(document).ready(function(){

  // originalFontSize
 var originalFontSize = $('.increase_fontsize').css('font-size');
 var maxFontSize = '20';
 // originalLineHeight
 var originalLineHeight = $('.increase_fontsize').css('line-height');
 
  //$("#font_size_t").click(function(){ 
  $('#font_size_t').live("click", function(){	
	// increase font size
	var currentFontSize = $('.increase_fontsize, .increase_fontsize *').css('font-size');
	var currentFontSizeNum = parseFloat(currentFontSize, 10);
	var newFontSize = currentFontSizeNum*1.2;
	$('.increase_fontsize, .increase_fontsize *').css('font-size', newFontSize);
	// increase line-height
	var currentLineHeight = $('.increase_fontsize, .increase_fontsize *').css('line-height'); 	
	var currentLineHeightNum = parseFloat(currentLineHeight, 10);   
	var newLineHeight = 2;
	$('.increase_fontsize, .increase_fontsize *').css('line-height', newLineHeight);	
	
	// reset
	if (newFontSize >= maxFontSize) {
			$('.increase_fontsize, .increase_fontsize *').css('font-size', originalFontSize);
			$('.increase_fontsize, .increase_fontsize *').css('line-height', originalLineHeight);
		}
		
	return false;	
  });
  
});







// external links open in new window
//-------------------------------------------------------------------
$(document).ready(function(){
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr({target: "_blank", title: "Open in new window"});
});


// Scroll to topLink
//-------------------------------------------------------------------
$(function(){$.fn.scrollToTop=function(options){if(options){var speed=options.speed;var ease=options.ease;}else{var speed="slow";var ease="jswing";}var scrollDiv=$(this);$(this).hide().removeAttr("href");if($(window).scrollTop()!="0"){$(this).fadeIn("slow");}$(window).scroll(function(){if($(window).scrollTop()=="0"){$(scrollDiv).fadeOut("slow");}else{$(scrollDiv).fadeIn("slow");}});$(this).click(function(event){$("html, body").animate({scrollTop:"0px"},speed,ease);});}});
$(function() {
	$("#toTop").scrollToTop({
		speed:500
		//ease:"easeOutBounce"
	});
});
			
// Smooth Scrolling  internal page links
//-------------------------------------------------------------------
$(function(){

    $('a[href*=#]').click(function() {
    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
        
            var $target = $(this.hash);
            
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            
            if ($target.length) {
            
                var targetOffset = $target.offset().top;
                
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                    
                return false;
                
            }
            
        }
        
    });
    
});
			

// MODULE:
// #######################################################


// TABS module
// ==========================================
$(document).ready(function() {
   
   $('.modul_title_tab').parent().parent().parent().tabs({ 
   		//selected: 1 ,
		cookie: { expires: 30 } ,
		cache: true,
		collapsible: true,
		fx: { height: 'toggle'}				
	});
   
});


// TOGGLE module
// ==========================================
$(document).ready(function(){  
	$('.modul_title_toggle',this).toggle(  
		function () {
			
			var modul_id = $(this).attr('id');
			var modul_title = $(this).attr('title');
			var modul_url = $(this).attr('rel');
			if (modul_url == null) {
				modul_url = '';
			};
			
			
			// LA DESCHIDERE:
			//-----------------------------
			// la prima incarcare...
			if($('#container_'+modul_id).text() == '') {  
				
				$(this).css({'background':'#e8e7e7','border-bottom':'none','color':'#333333'});
				
				$(this).html(modul_title+" <span title='inchide'>[-]</span>").append("<img class='loading_mod_img' src='../res_img/utils/loading6.gif'>");
				if (modul_url != '') { // daca avem modul_url ... il incarcam
					if ($('#container_'+modul_id).is('div')) {
							$('#container_'+modul_id).load(""+modul_url+"").slideDown(500); 
						}
						else {
							$('#container_'+modul_id).css({'display':'block'});
							$('#container_'+modul_id).attr("src",""+modul_url+"").slideDown(500);
						};
				} else { // altfel.. deschidem restrictNote
					$('#container_'+modul_id).slideDown(500); 
				};
				$(".loading_mod_img").fadeTo(1000, 0);
				$.cookie('#container_'+modul_id, 'expanded');  // write COOKIES

			// daca a mai fost incarcat odata ...
			} else { 
				
				$(this).css({'background':'#e8e7e7','border-bottom':'none','color':'#333333'});
				$(this).html(modul_title+" <span title='inchide'>[-]</span>");  
				$('#container_'+modul_id).slideDown(500); 
				$.cookie('#container_'+modul_id, 'expanded');  // write COOKIES
			}  
		},  
		
		// LA INCHIDERE:
		//-----------------------------
		function () {  
			var modul_id = $(this).attr('id');
			var modul_title = $(this).attr('title');
			$(this).html(modul_title+" <span title='deschide'>[+]</span>");  
			$("#container_"+modul_id).slideUp(500); 
			$(this).css({'background':'#e1e1e1','border-bottom':'1px solid #666666','color':'#333333'});
			$.cookie('#container_'+modul_id, 'collapsed');  // write COOKIES
		}  
	);

	/*
	// READ COOKIES
	//-----------------------------
	$(".modul_title_toggle").each(function(i) {
		var modul_id = $(this).attr('id');
		var modul_title = $(this).attr('title');
		var modul_url = $(this).attr('rel');
		if (modul_url == null) {
				modul_url = '';
			};

		if ($.cookie('#container_'+modul_id) == 'expanded') {
			$(this).html(modul_title+" <span title='inchide'>[-]</span>").append("<img class='loading_mod_img' src='../res_img/utils/loading6.gif'>");
			if (modul_url != '') { // daca avem modul_url ... il incarcam
				$(this).css({'background':'#e8e7e7','border-bottom':'none','color':'#333333'});
				if ($('#container_'+modul_id).is('div')) {
							$('#container_'+modul_id).load(""+modul_url+"").slideDown(500); 
						}
						else {
							$('#container_'+modul_id).attr("src",""+modul_url+"").slideDown(500); 
						};
				
			} else { // altfel.. deschidem restrictNote
				$('#container_'+modul_id).slideDown(500); 
			};
			$(".loading_mod_img").fadeTo(1000, 0);
		}
	});
	*/
	
});  


// thickbox
//-------------------------------------------------------------------
$(document).ready(function(){
	$(".linkopengal").each(function() {	//deschide galerie multimedia
		$(this).attr("href", $(this).attr("href") + "&KeepThis=true&TB_iframe=true&height=530&width=850");
	});
});




// thickbox live in module
//-------------------------------------------------------------------
$('.linkopengal').live("click", function () {
		$(this).addClass("thickbox");
		$(this).attr("href", $(this).attr("href") + "&KeepThis=true&TB_iframe=true&height=530&width=850");
		var t = this.title || this.name || null;
		var a = this.href || this.alt;
		var g = this.rel || false;
		tb_show(t,a,g);
		this.blur();
		return false;
});

$('.linkopenimg, .zoom_img_editor_link').live("click", function () {
		var t = this.title || this.name || null;
		var a = this.href || this.alt;
		var g = this.rel || false;
		tb_show(t,a,g);
		this.blur();
		return false;
});


// /END MODULE:
// #######################################################



// encript email address:
//-------------------------------------------------------------------
 function UnCryptMailto( s )
    {
        var n = 0;
        var r = "";
        for( var i = 0; i < s.length; i++)
        {
            n = s.charCodeAt( i );
            if( n >= 8364 )
            {
                n = 128;
            }
            r += String.fromCharCode( n - 1 );
        }
        return r;
    }

    function linkTo_UnCryptMailto( s )
    {
        location.href=UnCryptMailto( s );
    }
//-------------------------------------------------------------------/




// repair anchors link on web with BASE tag:
//-------------------------------------------------------------------
jQuery.repairLink2Anchor = function() {
    // exists tag BASE
    if ($("base").length) {
        // regular expression for anchor link
        var re1 = /#([\w-]+)/; // anchor parts
        var re2 = /^#([\w-]+)/; // only anchor
        // read current url
        var thisUrl = document.location.href;
        // remove anchor from current url
        thisUrl=thisUrl.replace(re1,"");
        // inicialization
        var href = '';
        var anchor = '';
        // loop all A tags whith attribute href
        $("a[href]").each(function(){
            href = $(this).attr("href");
            // check - href is anchor?
            if (re2.test(href)) {
                anchor = href.match(re2);
                $(this).attr("href", thisUrl + '#' + anchor[1]);
            }
        });
    }
}


/*start this jQuery function with:*/

$(document).ready(function(){
	$.repairLink2Anchor();
});
//-------------------------------------------------------------------/




