/*================================================
  scripturi JS valabile pe intreg siteul
  ================================================*/

var isHeaderFotoCaruselInit = false;
  
$(document).ready(function() {
	
    
    /**
     * Daca userul a ales sa nu vada pozele din header, le ascundem direct de pe-acum.
     */
    
    if( getCookie( "foto_head_show" ) == -1 || window.location == 'http://www.evive.ro/evenimente/poze' ) { 
    	//hideHeaderPictures();
    	$('div#wrapper_header').css("height", "135px");
		$('div.jcarousel-skin-tango').css("height", "5px");											
		$('#ultimele_evenimente_foto').css('height', '14px');
    } else {
    	$('ul#foto_carousel').show();	
    	initHeaderFotoCarusel();
    }    
       
    $('div#ultimele_evenimente_foto').click(function() {
		if( $('#ultimele_evenimente_foto div').length == 0 || $('#ultimele_evenimente_foto div').css('height') == '0px' ) {
			showHeaderPictures();
		} else {
			//hideHeaderPictures();
		}   	
		
    });
    
    $("img.promo_visible").hover(
		function() {
			$(this).animate({"opacity": "1"}, "fast");
		},
		function() {
			$(this).animate({"opacity": "0"}, "fast");
		});
    
	$(function () {
		// fade links
		$("a.img").fadeTo("fast", 0.8);
		$("a.img").mouseenter(function(){
			$(this).fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
		}).mouseleave(function(){
			$(this).fadeTo("fast", 0.8); // This should set the opacity back to 60% on mouseout
		});
		
		//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
		//Partial Sliding (varianta mea)
		$('.boxgrid.stanga').hover(function(){
			$(".cover", this).stop().animate({top:'0px', left:'-68px'},{queue:false,duration:300});
		}, function() {
			$(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});
		});
	});
	
	$('ul#mycarousel').show();
	if( $('#mycarousel').length != 0 ) {
	   $('#mycarousel').jcarousel({
			scroll: 1
	   });
	}
	
	$('ul#plcarousel').show();
	if( $('#plcarousel').length != 0 ) {
	   $('#plcarousel').jcarousel({
			scroll: 1
	   });
	}
		
	if( $('.entry').length != 0 ) {
		//$('.entry a img').parent().attr('rel','shadowbox[Post]');	
	}
	
	if( !strpos( window.location, '/colaboratori' ) && !strpos( window.location, '/parteneri' ) && !strpos( window.location, '/timisoara' ) ) {
		//Shadowbox.init();
		$('.entry a img').parent().fancybox({
				titlePosition: 'outside',
				transitionIn: 'elastic',
				onComplete: function(){
					_gaq.push(['_trackEvent', 'Poze', 'Fullsize', $("img#fancybox-img").attr("src") ]);
					// $("img#fancybox-img").attr("src")
				}
				/*transitionOut: 'fade',
				changeSpeed: 0*/
		});
		/*
		$.fancybox.next(function(){
				alert('next');
		});*/
	}	

	$('a').click(function() {
		if( (this.href+'').indexOf('evive.ro', (0 || 0)) === -1 &&
			(this.href+'').indexOf('flickr.com', (0 || 0)) === -1 &&
			(this.href+'').indexOf('javascript', (0 || 0)) === -1 &&
			(this.href+'').indexOf('linksalpha.com', (0 || 0)) === -1 &&
			(this.href+'').indexOf('ttp://', (0 || 0)) !== -1
		) {
			recordOutboundLink(this, 'Outbound Links', this.href );
			return false;
		}		
	});
	
	$('input#mce-EMAIL').val('adresa de email');
	$('input#mce-NAME').val('numele intreg');
	
	$('input#mce-EMAIL').click(function(){
		if( $('input#mce-EMAIL').val() == 'adresa de email' ) {
			$('input#mce-EMAIL').val('');
		}
	});
	
	$('input#mce-NAME').click(function(){
		if( $('input#mce-NAME').val() == 'numele intreg' ) {
			$('input#mce-NAME').val('');
		}
	});
	
	$('input#mce-EMAIL').blur(function(){
		if( $('input#mce-EMAIL').val() == '' ) {
			$('input#mce-EMAIL').val('adresa de email');
		}
	});
	
	$('input#mce-NAME').blur(function(){
		if( $('input#mce-NAME').val() == '' ) {
			$('input#mce-NAME').val('numele intreg');
		}
	});
	
	$('form#mc-embedded-subscribe-form').submit(function(){
		if( $('input#mce-EMAIL').val() == 'adresa de email' || $('input#mce-EMAIL').val() == '' ) {
			alert('Trebuie să introduceţi adresa dvs. de email.');
			return false;
		}
		if( ! validEmail( $('input#mce-EMAIL').val() ) ) {
			alert('Adresa de email introdusă nu este corectă. Vă rugam verificaţi şi încercaţi din nou.');
			return false;
		}
		if( $('input#mce-NAME').val() == 'numele intreg' || $('input#mce-NAME').val() == '' ) {
			alert('Trebuie să introduceţi numele dvs.');
			return false;
		}
		
		return true;
	});
	
	
}); /* END OF DOCUMENT-READY TASKS */

function initHeaderFotoCarusel() {
	if( isHeaderFotoCaruselInit ) return true;
	// carouselul de fotografii
	if( $('ul#foto_carousel').length == 0 ) $('ul#foto_carousel').show();
	$('#foto_carousel').jcarousel({
		scroll: 1,
		visible: 12,
		auto: 60,
		wrap: 'circular'
    });	
    isHeaderFotoCaruselInit = true;
    return true;
}

function showHeaderPictures() {
	$('div#wrapper_header').animate({ height: 220 });	
	$('ul#foto_carousel').show();
	$('div.jcarousel-skin-tango').animate({
			height: 80
		}, function(){ $('#ultimele_evenimente_foto div').css('height', '80px'); });
	
	$('#ultimele_evenimente_foto div').animate({ height: 80 });
	initHeaderFotoCarusel();	
	setCookie("foto_head_show", 1, 10 );
}

function hideHeaderPictures() {
	$('div#wrapper_header').animate({
		height: 135
	});			
	$('div.jcarousel-skin-tango').animate({
			height: 0
		}, function(){
			//$('#ultimele_evenimente_foto div').hide();
			$('#ultimele_evenimente_foto div').css('height', '0px');
	});
	setCookie("foto_head_show", -1, 10 );
}

/**
 * Inregistram linkurile prin care se pleaca de pe site
 */
function recordOutboundLink(link, category, action) {
  try {
	//var myTracker=_gat._getTrackerByName();
	//_gaq.push(['myTracker._trackEvent', category, action ]);
	_gaq.push(['_trackEvent', category, action ]);
	setTimeout('document.location = "' + link.href + '"', 200)
	//setTimeout('openInNewWindow("' + link.href + '")', 100);
	
  }catch(err){
  	 alert('err!');
  }
}

function openInNewWindow( href ) {
	// Change "_blank" to something like "newWindow" to load all links in the same new window
	var newWindow = window.open( href, '_blank');
	newWindow.focus();
	return false;
}

function validEmail(email) {
	 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
	 return email.match(re)
}


