
jQuery.log = function(message) { if(window.console) { console.debug(message); } else { alert(message);}};

$(function() {

	//blur links and submit buttons
	$('a,input[type=submit]').click(function(){$(this).blur();});

	//tabs
	$("ul.tabSmall,ul.tabBig").not('.external_tab').tabs("div.inner_tab > div",{
		effect:'fade',
		initialIndex: -1
	});
	//$("ul.tabSmall a").removeClass("current");

	//Afi about page
	$('#buttons_afipalace a').click(function(ev){
		var $O_butt = $('#buttons_afipalace a.buttonSmallBlueCurr');
		var curr_link = $('#buttons_afipalace a.buttonSmallBlueCurr').attr('rel');
		var $O_target = $('#' + curr_link);

		if ( $('.show').attr('id') != $(this).attr('rel')  )
		{
			$O_butt.removeClass('buttonSmallBlueCurr');
			$(this).addClass('buttonSmallBlueCurr');
			$O_target.removeClass('show');
			$O_target.hide();
			$('#' + $(this).attr('rel')).fadeIn().addClass('show');
		}
	});

	//Shopping Map pointing
	$("#shoppingList li a").hover(
	function () {
		thisMovie("mall_map").pointOnMap(this.href);
	},
	function () {
		thisMovie("mall_map").endPointing();
	});

	//shpping logo preview
	screenshotPreview();

	//lightbox
	$("a[rel^='prettyPhoto']").prettyPhoto();





	$('#movies-container').jScrollPane({
		showArrows:false,
		scrollbarWidth: 10,
		reinitialiseOnImageLoad: true
	});



	$('#shoppingList').listnav({
		//initLetter: 'a',
		includeAll: true,
		includeOther: false,
		flagDisabled: true,
		noMatchText: 'Nici un magazin cu aceasta litera',
		showCounts: false,
		cookieName: 'shopping-list',
		onClick: function(letter){ $('ul.sc_menu a').removeClass('selected')}
		//prefixes: ['the','a']
	});


	$('#fdList').listnav({
		//initLetter: 'a',
		includeAll: true,
		includeOther: false,
		flagDisabled: true,
		noMatchText: 'Nici un magazin cu aceasta litera',
		showCounts: false,
		cookieName: 'fd-list'
		//onClick: function(letter){ alert('You clicked ' + letter); },
		//prefixes: ['the','a']
	});

	$('#funList').listnav({
		//initLetter: 'a',
		includeAll: true,
		includeOther: false,
		flagDisabled: true,
		noMatchText: 'Nici o distractie cu aceasta litera',
		showCounts: false,
		cookieName: 'fun-list'
		//onClick: function(letter){ alert('You clicked ' + letter); },
		//prefixes: ['the','a']
	});


	$('#calendar').fullCalendar({
		header: {
			left: 'title',
			center: 'today',
			right: 'prev,next '
		},

		loading: function(bool) {
			//if(bool) $('#loading').show();
			//else $('#loading').hide();
		},
		eventMouseover: function(calEvent, jsEvent, view){
			$('.ev_tooltip[title]').tooltip({tip: '.tooltip', effect: 'slide'}).dynamic( {

				// customized configuration on bottom edge
				bottom: {

					// slide downwards
					direction: 'down',

					// bounce back when closed
					bounce: true
				}
			})
		},

		eventMouseout: function(calEvent, jsEvent, view){

		},
		events: "events/jsonEvents"

	});


	$('#gallery').galleryView({
		panel_width: 450,
		panel_height: 340,
		frame_width: 80,
		frame_height: 80,
		transition_speed: 500,
		background_color: 'transparent',

		easing: 'easeInOutBack',
		pause_on_hover: true,
		nav_theme: 'dark',
		overlay_height: 80,
		filmstrip_position: 'bottom'
	});



	$('#gallery_cinema').galleryView({
		panel_width: 450,
		panel_height: 339,
		frame_width: 80,
		frame_height: 118,
		transition_speed: 500,
		background_color: 'transparent',
		border:'none',
		easing: 'easeInOutBack',
		pause_on_hover: true,
		nav_theme: 'dark',
		overlay_height: 118,
		filmstrip_position: 'bottom'
	});





	$('#promo_box').cycle({speed:  500,timeout:3000 })


	$('#newsl_email').focus(function(){$(this).val('')});
	$('#newsl-form').submit(function() {
		$(this).ajaxSubmit({
			dataType:  'json',
			success: function(data){
				if(data.error  != true)
				{
					var message = '<span class="info">'+data.message+'</span>';
				}
				else
				{
					var message = '<span class="error">'+data.message+'</span>';
				}
				$('#newsl-message').html(message);
				$('#newsl_email').val('E-mail');
				setTimeout(function() {$('#newsl-message').html('&nbsp;');}, 5000);
			}
		});
		return false;
	});





	if(siteMessage != '' ) {
		$.gritter.add({
			title: '<span class="message">Mesaj</span>',
			text: siteMessage,
			sticky: false,
			time: '4000'
		});
	}


	$(".signin").click(function(e) {
		e.preventDefault();
		$("fieldset#signin_menu").toggle();
		$(".signin").toggleClass("menu-open");
	});

	$("fieldset#signin_menu").mouseup(function() {
		return false
	});
	$(document).mouseup(function(e) {
		if($(e.target).parent("a.signin").length==0) {
			$(".signin").removeClass("menu-open");
			$("fieldset#signin_menu").hide();
		}
	});


	$(".table_info tbody tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
	$(".table_info tbody tr:even").addClass("alt");


	/* Accordion */
	$(".accordion ul").hide();
	$(".accordion h3.selected").next("ul").show();
	$(".accordion h3").click(function() {
		$(this).next("ul")
		.slideToggle(500)
		.siblings("ul:visible").slideUp({ duration: 1000, easing: 'easeOutExpo' });
		$(this).toggleClass("selected");
		$(this).siblings("h3").removeClass("selected");
		return false;
	});



	//Get our elements for faster access and set overlay width
	var $shopping_tags = $('div.sc_menu'),
	$ul_tags = $('ul.sc_menu'),
	// unordered list's left margin
	ulPadding = 15;

	//Get menu width
	var divWidth = $shopping_tags.width();

	//Remove scrollbars
	$shopping_tags.css({overflow: 'hidden'});

	//Find last image container
	var lastLi = $ul_tags.find('li:last-child');

	//When user move mouse over menu
	$shopping_tags.mousemove(function(e){

		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

		var left = (e.pageX - $shopping_tags.offset().left) * (ulWidth-divWidth) / divWidth;
		$shopping_tags.scrollLeft(left);
	});

	$.each($ul_tags.children(),function(i,el){
		$(el).children().click(function(ev){
			$ul_tags.find('a').removeClass('selected');
			$('#shoppingList-nav a').removeClass('ln-selected');
			//$.log($(el).children());
			var tag = $(this).text();
			$('#shoppingList li').hide();
			$('#shoppingList li[title*='+tag+']').show();
			$(this).addClass('selected');

			return false;
		})

	});





});



function thisMovie(movieName) {


	if (window.document[movieName])
	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName];
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
		return document.getElementById(movieName);
	}

}


$.easing.custom = function (x, t, b, c, d) {
	var s = 1.70158;
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}


this.screenshotPreview = function(){
	/* CONFIG */

	xOffset = 10;
	yOffset = 30;

	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result

	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		if(this.rel)
		{
			$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='loading...' />"+ c +"</p>");
		}
		else
		{
			$("body").append("<p id='screenshot' style='padding:0 20px 20px 20px;font-size:1.2em'>"+ c +"</p>");
		}
		$("#screenshot")
		.css("top",(e.pageY - xOffset) + "px")
		.css("left",(e.pageX + yOffset) + "px")
		.fadeIn("fast");
	},
	function(){
		this.title = this.t;
		$("#screenshot").remove();
	});
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
		.css("top",(e.pageY - xOffset) + "px")
		.css("left",(e.pageX + yOffset) + "px");
	});
};

// Cycle lite plugin

(function(D){var A="Lite-1.0";D.fn.cycle=function(E){return this.each(function(){E=E||{};if(this.cycleTimeout){clearTimeout(this.cycleTimeout)}this.cycleTimeout=0;this.cyclePause=0;var I=D(this);var J=E.slideExpr?D(E.slideExpr,this):I.children();var G=J.get();if(G.length<2){if(window.console&&window.console.log){window.console.log("terminating; too few slides: "+G.length)}return }var H=D.extend({},D.fn.cycle.defaults,E||{},D.metadata?I.metadata():D.meta?I.data():{});H.before=H.before?[H.before]:[];H.after=H.after?[H.after]:[];H.after.unshift(function(){H.busy=0});var F=this.className;H.width=parseInt((F.match(/w:(\d+)/)||[])[1])||H.width;H.height=parseInt((F.match(/h:(\d+)/)||[])[1])||H.height;H.timeout=parseInt((F.match(/t:(\d+)/)||[])[1])||H.timeout;if(I.css("position")=="static"){I.css("position","relative")}if(H.width){I.width(H.width)}if(H.height&&H.height!="auto"){I.height(H.height)}var K=0;J.css({position:"absolute",top:0,left:0}).hide().each(function(M){D(this).css("z-index",G.length-M)});D(G[K]).css("opacity",1).show();if(D.browser.msie){G[K].style.removeAttribute("filter")}if(H.fit&&H.width){J.width(H.width)}if(H.fit&&H.height&&H.height!="auto"){J.height(H.height)}if(H.pause){I.hover(function(){this.cyclePause=1},function(){this.cyclePause=0})}D.fn.cycle.transitions.fade(I,J,H);J.each(function(){var M=D(this);this.cycleH=(H.fit&&H.height)?H.height:M.height();this.cycleW=(H.fit&&H.width)?H.width:M.width()});J.not(":eq("+K+")").css({opacity:0});if(H.cssFirst){D(J[K]).css(H.cssFirst)}if(H.timeout){if(H.speed.constructor==String){H.speed={slow:600,fast:200}[H.speed]||400}if(!H.sync){H.speed=H.speed/2}while((H.timeout-H.speed)<250){H.timeout+=H.speed}}H.speedIn=H.speed;H.speedOut=H.speed;H.slideCount=G.length;H.currSlide=K;H.nextSlide=1;var L=J[K];if(H.before.length){H.before[0].apply(L,[L,L,H,true])}if(H.after.length>1){H.after[1].apply(L,[L,L,H,true])}if(H.click&&!H.next){H.next=H.click}if(H.next){D(H.next).bind("click",function(){return C(G,H,H.rev?-1:1)})}if(H.prev){D(H.prev).bind("click",function(){return C(G,H,H.rev?1:-1)})}if(H.timeout){this.cycleTimeout=setTimeout(function(){B(G,H,0,!H.rev)},H.timeout+(H.delay||0))}})};function B(J,E,I,K){if(E.busy){return }var H=J[0].parentNode,M=J[E.currSlide],L=J[E.nextSlide];if(H.cycleTimeout===0&&!I){return }if(I||!H.cyclePause){if(E.before.length){D.each(E.before,function(N,O){O.apply(L,[M,L,E,K])})}var F=function(){if(D.browser.msie){this.style.removeAttribute("filter")}D.each(E.after,function(N,O){O.apply(L,[M,L,E,K])})};if(E.nextSlide!=E.currSlide){E.busy=1;D.fn.cycle.custom(M,L,E,F)}var G=(E.nextSlide+1)==J.length;E.nextSlide=G?0:E.nextSlide+1;E.currSlide=G?J.length-1:E.nextSlide-1}if(E.timeout){H.cycleTimeout=setTimeout(function(){B(J,E,0,!E.rev)},E.timeout)}}function C(E,F,I){var H=E[0].parentNode,G=H.cycleTimeout;if(G){clearTimeout(G);H.cycleTimeout=0}F.nextSlide=F.currSlide+I;if(F.nextSlide<0){F.nextSlide=E.length-1}else{if(F.nextSlide>=E.length){F.nextSlide=0}}B(E,F,1,I>=0);return false}D.fn.cycle.custom=function(K,H,I,E){var J=D(K),G=D(H);G.css({opacity:0});var F=function(){G.animate({opacity:1},I.speedIn,I.easeIn,E)};J.animate({opacity:0},I.speedOut,I.easeOut,function(){J.css({display:"none"});if(!I.sync){F()}});if(I.sync){F()}};D.fn.cycle.transitions={fade:function(F,G,E){G.not(":eq(0)").css("opacity",0);E.before.push(function(){D(this).show()})}};D.fn.cycle.ver=function(){return A};D.fn.cycle.defaults={timeout:4000,speed:1000,next:null,prev:null,before:null,after:null,height:"auto",sync:1,fit:0,pause:0,delay:0,slideExpr:null}})(jQuery)