// JavaScript Document
function activateLink(element,parent){
	$(element)
		.parents(parent)
			.find('a').removeClass("selected")
			.end()
		.end()
	.addClass("selected");
	//console.log(element);
}
/*function activateLink2(){
	$(this)
		.parents("table")
			.find('a').removeClass("selected")
			.end()
		.end()
	.addClass("selected");
	
}
function trigger(data) {
  var el = $('#left_links table').find('a[href$="' + data.id + '"]').get(0);
  activateLink2.call(el);
}*/
function setTop(){
	margin=(document.documentElement.clientHeight-665)/2;
	if(margin<0) margin=0;
	return margin;
}
function debug()
{
	console.log(this);
}
$(function() {
	$("#oferta_link").click(function() {
        $.fancybox({
            //'orig'            : $(this),
            'padding'       : 0,
            'href'          : 'oferta/oferta.jpg',
            'title'         : 'Oferta lunii august Decorama',
            'transitionIn'  : 'elastic',
            'transitionOut' : 'elastic'
        });
    });
	//alert(setTop());
	$(".floating").css('margin-top',setTop());
	// initialize scrollable
	//$("#main_wrapper").scrollable().navigator("#left_links");
	$('#main_wrapper').css('overflow','hidden');
	$('.lista_produse').css('overflow','hidden');
	$('#produse_wrapper').css('overflow','hidden');
	$('.scroller_galerie').css('overflow','hidden');
	$('.white_bg').css('overflow','hidden');
	$.localScroll.defaults.axis = 'xy';
	$("#left_links").find('a').click(function(){activateLink(this,'._blank')});
	$(".lista_produse").find('a').click(function(){activateLink(this,'ul')});
	$(".linkuri").find('a').click(function(){activateLink(this,'.linkuri')});
	//$('#main_wrapper').serialScroll(scrollOptions);
    $('.scroller_galerie').find('img').click(function(){
		var sursa=this.src;
		var container='#poza_'+this.alt;
		//console.log($(container));
		$(container).fadeOut('slow',function(){
			var el=$(container).find('img').get(0);
			el.src=sursa;
			$(container).fadeIn('slow');
			});
			//console.log(el);
		});
    // Scroll initially if there's a hash (#something) in the url 
    $("#left_links").localScroll({
        target: '#main_wrapper', // Could be a selector or a jQuery object too.
        queue:true,
		//hash:true,
        duration:500
    });
	$(".lista_produse").localScroll({
        target: '#produse_wrapper', // Could be a selector or a jQuery object too.
        queue:true,
		//hash:true,
        duration:500
    });
	if (window.location.hash) {
  		//trigger({ id : window.location.hash.substr(1) });
	}
	$('.scroller_galerie').serialScroll({
		items:'li',
        prev:'.galerie_produse a.prev',
        next:'.galerie_produse a.next',
        duration:500,
		offset: -170,
		start: 2,
		stop: true,
        //force:true,
        cycle:true,
		step: 3
        //jump: true
	});
	$('.lista_produse').serialScroll({
		items:'li.item',
        prev:'#navigare_produse a.prev',
        next:'#navigare_produse a.next',
        duration:500,
		offset: -534,
		start:4,
		stop: true,
        //force:true,
        cycle:false
        //jump: true
	});
	$('.slider').slideshow({
		height:385,
		width:385,
        title:false,
        playframe:false,
        play:true,
        effect:'random',
        help:'Effect "random"'
    });
	$('.scroll-pane').jScrollPane();
});
 var flashvars = {};
        var params = {
            wmode: "transparent" 
        };
        var attributes = {};
        swfobject.embedSWF("flash/sound2.swf", "sound", "80", "30", "9.0.0","expressInstall.swf", flashvars, params, attributes);
function loadComplete(){
	document.getElementById('loader').style.display='none';
	document.getElementById('loader').style.visibility='hidden';
}
function changeVideo(url){
	html='<object width="385" height="265"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="'+url+'" /><embed src="'+url+'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="385" height="265"></embed></object>';
	document.getElementById('video').innerHTML=html;
}

