$(document).ready(function() {
    $("body").addClass("js");
});

$(document).ready(function() {
    $("#opPopup").click(function(){
        $("#popupbox").show();
    });
    
    $("#popupbox").hover(function(){
    
    },function(){
        $("#popupbox").hide();
    });
});


//FAN BOX
$(document).ready(function() {
    $(".facebook-link.kikiBkg").hover(function(){
        $("#fan-box").show();
    },function(){
        checkFanBox();
    });
    
    $("#fan-box").hover(function(){
        $(this).addClass("active");
    },function(){
        $(this).removeClass("active");
        checkFanBox();
    });
    
    function checkFanBox(){
        setTimeout(function(){
            if(!$("#fan-box").is(".active")){
              $("#fan-box").hide();
            }
        },1000);
    }
});

//FAN BOX 2
$(document).ready(function() {
    $(".facebook-link.dorinaBkg").hover(function(){
        $("#fan-box-2").show();
    },function(){
        checkFanBox();
    });
    
    $("#fan-box-2").hover(function(){
        $(this).addClass("active");
    },function(){
        $(this).removeClass("active");
        checkFanBox();
    });
    
    function checkFanBox(){
        setTimeout(function(){
            if(!$("#fan-box-2").is(".active")){
              $("#fan-box-2").hide();
            }
        },1000);
    }
});

//FAN BOX ALL
$(document).ready(function() {
    $('.facebook-link').hover(function(){
        $('.fan-box[rel='+ $(this).attr('rel') +']').show().addClass('active');
		},function(){
				$('.fan-box[rel='+ $(this).attr('rel') +']').removeClass('active');
        checkFanBox( $(this).attr('rel') );
    });
    
    $('.fan-box').hover(function(){
        $(this).addClass('active');
    },function(){
        $(this).removeClass('active');
        checkFanBox( $(this).attr('rel') );
    });
    
    function checkFanBox( relation ){
        setTimeout(function(){
            if(!$('.fan-box[rel='+relation+']').is('.active')){
              $('.fan-box[rel='+relation+']').hide();
            }
        },1000);
    }
});


//  LANGUAGE DROPDOWN
$(document).ready(function() {
    var activeLang = $("#lang-drop .active").html();
    var listLang = $("#lang-drop").html();
    $("#lang-drop").wrap('<div id="lang-wrapper"></div>');
    $("#lang-wrapper").append('<span>'+activeLang+'</span><ul id="lang-dropdown">'+listLang+'</ul>');
    $("#lang-dropdown").find(".active").remove();
    $("#lang-wrapper span,#lang-dropdown a").click(function(){
        if ($("#lang-dropdown").is(":visible")){$("#lang-dropdown").slideUp();}
        else {$("#lang-dropdown").slideDown();}
    });
});

//  POLL
$(document).ready(function() {
    $("#poll .go").bind("click",function(){
        openPoll();
    });
});

function openPoll(){
    var offset = $("#poll").offset();
    $("select").css("visibility","hidden");
    $("body").append('<div id="poll-overlay" title="zatvori"></div><div id="poll-popup"><img src="images/close-button.gif" class="close" alt="" />'+$("#poll").html()+'</div>');
    $("#poll-overlay").css({ height:$(document).height(), width:$(document).width(), opacity: "0.8" });
    $("#poll-popup").css({ right: offset.left-120, top: offset.top }).show();
    $(window).resize(function(){
        $("#poll-overlay").css({ height:$(document).height(), width:$(document).width(), opacity: "0.8" });
        var offset = $("#poll").offset();
        $("#poll-popup").css({ left: offset.left-112, top: offset.top }).show();
    });
    $("#poll-overlay,#poll-popup .close").click(function(){
        $("#poll-popup").remove();
        $("#poll-overlay").remove();
        $(window).unbind("resize");
        $("#poll .go").bind("click",function(){
            openPoll();
        });
    });
    
}

//  GENERAL
$(document).ready(function() {
    $(".finAccordion dt:first").addClass("active");
    $(".finAccordion dd:first").addClass("active");

    $(".finAccordion dd").not(".active").hide();
    $(".finAccordion dt").click(function(){
        $(".finAccordion dt").removeClass("active");
        $(".finAccordion dd").removeClass("active");
        $(".finAccordion dd").slideUp();
        $(this).addClass("active");
        $(this).next("dd").slideDown().addClass("active");
    });
    
    $(".finAccordion2 dt:first").addClass("active");
    $(".finAccordion2 dd:first").addClass("active");

    $(".finAccordion2 dd").not(".active").hide();
    $(".finAccordion2 dt").click(function(){
        if ( $(this).is(".active") ) {
            $(".finAccordion2 dt").removeClass("active");
            $(".finAccordion2 dd").removeClass("active");
            $(".finAccordion2 dd").slideUp();
            $(".finAccordion2 dd div").slideUp();
            return false;
        }
        $(".finAccordion2 dt").removeClass("active");
        $(".finAccordion2 dd").removeClass("active");
        $(".finAccordion2 dd").slideUp();
        $(".finAccordion2 dd div").slideUp();
        $(this).addClass("active");
        $(this).next("dd").slideDown().addClass("active");
    });

    $(".finAccordion2 dd div").hide();
    
    $(".finAccordion2 dd .title").click(function(){
       
        var elWrap  = $(this).parents("dl");
        if ( $(this).is(".active") ) {
            $(".finAccordion2 dd .title").removeClass("active");
            $(".finAccordion2 dd div").removeClass("active").slideUp();
            return false;
        }
        $(".finAccordion2 dd .title").removeClass("active");
        $(".finAccordion2 dd div").removeClass("active").slideUp();
        $(this).addClass("active");
        $(this).next("div").slideDown().addClass("active");
    });    
});

// TOU POPUP
$(document).ready(function(){
  $('a.link_tou').click(function(event){
    if($("#tou_holder").html()!=null){
        $('#tou_holder').remove();
        return false;
    }
    
    var touClose='';
    var touLink=$(this).attr('href');
    $(this).attr('href').match(/tou_hr/ig) ? touClose='Zatvori' : touClose='Close';
    $('body').append('<div id="tou_holder"></div>');
    $('#tou_holder').hide().css({'top':'180px'}).fadeIn(300,function(){$(this).append('<iframe src="'+phrasebook.URLROOT+'/'+touLink+'" width="480" height="480" frameborder="0" scrolling="auto" />')});
    $('#tou_holder').append('<a class="close">'+touClose+'</a>').bind('click',function(){$('#tou_holder').remove()});
    return false;
  });
  
});

// INNER FLASH VIDEO
/* <div id="inner_flash_video_01" class="inner_flash_video"></div> */
$(document).ready(function(){
    $(".inner_flash_video").each(function(){
        var link = $(this).attr("rel").split("|");
        var videoElpopup = new SWFObject(phrasebook.URLROOT+"/video/player.swf", "flasholder", "380", "242", "9", "#fff");
        videoElpopup.addParam("wmode", "transparent");
        videoElpopup.addParam("allowscriptaccess", "always");
        videoElpopup.addParam("allowfullscreen", "true");
        videoElpopup.addVariable("file", phrasebook.URLROOT+link[0]);
        videoElpopup.addVariable("skin", phrasebook.URLROOT+"/video/skin.swf");
        videoElpopup.addVariable("image", phrasebook.URLROOT+link[1]);
        videoElpopup.addVariable("controlbar", "over");
        videoElpopup.write($(this).attr("id"));
    });
});

//HOME-SLIDESHOW
$(document).ready(function() {
	$('.col-3 .home_box.rotator .item_wrapper, .col-2 .home_box.new_products .item_wrapper').css('opacity', '0');
	if ($.browser.msie) {
		$('.col-3 .home_box.rotator, .col-2 .home_box.new_products').css('background', 'black');
	}
});

$(window).load(function() {
	if ($('#background_slideshow').length) {
		$('.col-3 .home_box.rotator .item a img').each(function() {
			var Hght = $(this).height();
			$(this).css('margin-top', (250-Hght)/2-8);
		});
		$('#background_slideshow').cycle({
			fx: 'fade',
			timeout: 8000,
			slideResize: 0
		});
		$('.col-2 .home_box.new_products .item_wrapper').cycle({
			fx: 'fade',
			timeout: 5000,
			pager: '#nav',
			slideResize: 0,
			before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
				$('.col-2 .home_box.new_products .item_wrapper').animate({
					height: $(nextSlideElement).height()
					}, 500, function() {

				});

			}
		});
		$('.col-2 .home_box.new_products .item_wrapper div.plus').live('click', function() {
				var shortH = $(this).parent().find('div.short').height();
				var longH = $(this).siblings('div.long').height();
				var wrapperH = $('.col-2 .home_box.new_products .item_wrapper').height();
			if ($(this).hasClass('on')) {
				$(this).removeClass('on');
				$('.col-2 .home_box.new_products .item_wrapper').animate({
					height: wrapperH + shortH - longH
					}, 500, function() {
//					$(this).find('.item:visible div.short').show();
//					$(this).find('.item:visible div.long').hide();
				});
				$(this).siblings('div.short').show();
				$(this).siblings('div.long').hide();
				}
			else {
				$(this).addClass('on');
				$(this).siblings('div.short').hide();
				$('.col-2 .home_box.new_products .item_wrapper').animate({
					height: wrapperH - shortH + longH
					}, 500, function() {

				});
				$(this).siblings('div.long').show();
				}
		});
		$('.col-3 .home_box.rotator .item_wrapper').cycle({
			fx: 'scrollDown',
			timeout: 3500,
			speedIn:  2000,
			speedOut: 500,
			easeIn:  'bounceout',
			easeOut: 'backin'
		});
		$('.col-3 .home_box.rotator .item_wrapper, .col-2 .home_box.new_products .item_wrapper').fadeTo(500, 1);
	}
});
