(function($){
    $(document).ready(function(){
        $('#top_right_arrows').fixpng();
        var setPopupWidth=function(){
        	var container = $('.topContainer');
            $('.modalMask').css({'width':$(window).width()+'px','height':$(window).height()+'px'});     
            $('#thornPopup').css({'left':(container.offset().left+260)+'px'});
        }
        setPopupWidth();
        
        $(window).bind('resize',function(){
            setTimeout(function(){
                setPopupWidth();
            },0);
        });
        
        $('td','.lightbox_drawer').bind('click',function(){
        	var id = this.className.match(/\d+/)[0];
           	if ($.browser.msie){
		        window['Thorn'].openDrawer(id);
		    }else{
		        document['Thorn'].openDrawer(id);
		    }        	
        });
        
        voltimum.lightbox = new voltimum.app.window({
        	container:'thornPopup'
        });
        
        voltimum.lightbox.get = function(id){
        	this.container.html('');
			this.open();
			this.load('/lightbox/productlist/'+id,'thornPopup');
        };

        voltimum.lightbox.onopen = function(tab){
            $('.modalMask').show();
        }
        voltimum.lightbox.onclose = function(tab){
            $('.modalMask').hide();
           	if ($.browser.msie){
		        window['Thorn'].closeDrawers();
		    }else{
		        document['Thorn'].closeDrawers();
		    }
        }
		
		voltimum.lightbox.bindEvents = function(){
	        $('.popup_menu','#thornPopup').bind('click',function(){
	            if($(this).hasClass('popup_menu_close')){
	                voltimum.lightbox.close();
	                return false;
	            }
	            if($(this).hasClass('popup_menu_active')){return false;}
	            $('.popup_menu','#thornPopup').removeClass('popup_menu_active');
	            $(this).addClass('popup_menu_active');
	            var url=$(this).attr('id').split('_').join('/');
	            //location.hash=$(this).attr('id');
	            voltimum.lightbox.load(url,'thornPopup');
	        });
        	$('.thornBoxContainerItemBtn','#thornPopup').bind('click',function(){
        		var id=$(this).attr('id').match(/\d+/)[0];
        		//location.hash='_lightbox_overview_'+$(this).attr('id');
            	voltimum.lightbox.load('/lightbox/overview/'+id,'thornPopup');
            });
            //images//
            $('.imageLeft,.imageRight','.lightboxRight').bind('click',function(){
            	var path = $(this).find('img').attr('src').split('/90/').join('/400/');
            	$('#lightContentBigimage').attr({'src':path});
            });
/*
            $('.applicationLink').each(function(){
            	if(typeof voltimum =='undefined' || !voltimum.areas || !voltimum.areas[$(this).text()]){
            		$(this).css({'background-color':'#FFDDDD'});
            	}            	
            }).bind('click',function(){
            	if(typeof voltimum =='undefined' || !voltimum.areas || !voltimum.areas[$(this).text()]){
            		return false;
            	}
            	document.location = voltimum.areas[$(this).text()];
            });
*/
		};
		
		$('#thornBoxContainerImage2').bind('click',function(){
			voltimum.lightbox.open();
			voltimum.lightbox.load('/lightbox/video','thornPopup');
			
		});
		
		var hiddenListHeight = $('#thornBoxScrollContainer').height() - $('#thornBoxScrolledContent').height();
		$('#scrollDownArrow').bind('click',function(){
			if(hiddenListHeight < 0 && $('#thornBoxScrolledContent').css('marginTop')=='0px'){
				$('#thornBoxScrolledContent').animate({'marginTop':hiddenListHeight+'px'},500);			
			}	
		});
		$('#scrollUpArrow').bind('click',function(){
			$('#thornBoxScrolledContent').animate({'marginTop':'0px'},500);
		});		
        
    });
}(voltimum.jQuery));
