//Cufon.replace('.specialtext p');
//Cufon.replace('h3 span');
//Cufon.replace('.back h3');

$('document').ready(function() {

              
    var hash = document.location.pathname.replace(/#/g, "");
    hash = hash.replace(/.html/g, "");
    var path = hash.split("/");  
    
    if (path [2] == 'portfolio')
    {
        if ($ (window).width () > 1000)
        {
            $ ('#container').css ('width', $ (window).width () - 240  + 'px');
        }
        $ (window).resize(function() {
            if ($ (window).width () > 1000)
            {
                $ ('#container').css ('width', $ (window).width () - 240  + 'px');
                
            }
        });
    }
    
    if (path [2] == 'klanten')
    {
        if ($ (window).width () > 1000)
            $ ('.klanten').css ('width', $ (window).width () - 240  + 'px');
        
        $ (window).resize(function() {
            if ($ (window).width () > 1000)
                $ ('.klanten').css ('width', $ (window).width () - 240  + 'px');
        });
    } 
    
    if (path [2] == 'over-ons' && $ ('.members').length > 0)
    {
        //$ ('.members').css ('width', $ (window).width () - 240  + 'px');
        
        $ (window).resize(function() {
            if ($ (window).width () - 240 < 921)
                $ ('.members').css ('width', $ (window).width () - 240  + 'px');
        });
    } 
    
    $ ('#over-ons .element .image').hover (function (){
        if ($ (this).next ().attr ('src') != '/')
        {
            var img = $ (this).attr ('src');
            $ (this).attr ('src', $ (this).next ().attr ('src')); 
            $ (this).next ().attr ('src', img);    
        }
    },function (){
        if ($ (this).next ().attr ('src') != '/')
        {
            var hvr = $ (this).attr ('src');
            $ (this).attr ('src', $ (this).next ().attr ('src')); 
            $ (this).next ().attr ('src', hvr);
        }
    });
    
    $ ('.site .b .image').hover (function (){
        if ($ (this).next ().attr ('src') != '/')
        {
            var img = $ (this).attr ('src');
            $ (this).attr ('src', $ (this).next ().attr ('src')); 
            $ (this).next ().attr ('src', img);    
        }
    },function (){
        if ($ (this).next ().attr ('src') != '/')
        {
            var hvr = $ (this).attr ('src');
            $ (this).attr ('src', $ (this).next ().attr ('src')); 
            $ (this).next ().attr ('src', hvr);
        }
    });
    
    if ($('#container').length > 0)
    {
        $container = $('#container')
        , incr                  = 0
        , columnWidth           = 296
        , animationDuration     = 800
        , activeVideo			= false
        , shiftNav 				= false;
        //catalystId				= s_gi('channel4dotcomdev');  
        
        
        $container.isotope({
            itemSelector : '.element',
            masonry: {columnWidth:232},
            //fitRows: {columnWidth: 306},
            //layoutMode : 'masonry', 
            //animationOptions        : { duration: animationDuration },
            //itemPositionDataEnabled : true,
            masonryHorizontal : {
            rowHeight: 232
            },
            cellsByRow : {
            columnWidth : 464,
            rowHeight : 464
            },
            cellsByColumn : {
            columnWidth : 464,
            rowHeight : 464
            },
            sortBy: 'order',
            sortAscending : false,
            getSortData: {
            
            order : function( $elem ) {
              return parseInt($elem.attr('data-order'));
            },    
            symbol : function( $elem ) {
              return $elem.attr('data-symbol');
            },
            category : function( $elem ) {
              return $elem.attr('data-category');
            }
            
            }
        
        });	
        
        
        
        $ ('#options .option-set .selected').removeClass ('selected');
        
        
        
        $.openItem($container);
        $.initNav($container); 
        $.screenScroll();
        $.bookmarked();
    }
    $ ('.case-default,.portfolio-default').hover (function (){
        //$ (this).prev ().animate ({opacity:1}, 500);
        $ (this).children ('.lines').animate ({opacity:0}, 500);
    },function (){
        //$ (this).prev ().animate ({opacity:0.35}, 500);
        $ (this).children ('.lines').animate ({opacity:1}, 500);
    });
    /*
    $ ('.case-default .lines,.portfolio-default .lines').mouseout (function (){
        //$ (this).prev ().animate ({opacity:0.35}, 500);
        $ (this).animate ({opacity:1}, 500);
    });
    
    $ ('.case-default h3,.portfolio-default h3').mouseover (function (){
        //$ (this).prev ().animate ({opacity:1}, 500);
        if ($ (this).parent ().children ('.lines').css ('opacity') == 1)
                $ (this).parent ().children ('.lines').animate ({opacity:0}, 500);
    });
    
    $ ('.case-default h3,.portfolio-default h3').hover (function (){
        //$ (this).prev ().animate ({opacity:0.35}, 500);
        alert ($ (this).parent ().children ('.lines').ismouseover());
        if (!$ (this).parent ().children ('.lines').ismouseover())
                $ (this).parent ().children ('.lines').animate ({opacity:1}, 500);
    });
    */
    //$.openItem($container);
    //$.social();
    //$.applyScroll($container); 
    
    //$.wordSet();
    //$.more();
    
    $ ('.lang a').click (function (){
    
    var url = window.location.pathname.replace ('.html', '').split ('/');
    
    $.ajax({
    	url: "/item.php",	
    	type: "GET",		
    	data: 'klanten=' + (url.length > 2 && url [3] != 'cases' && url [3] != 'werk' && url [3] != 'portfolio' ? url [3] : '') + '&id=' + ($ ('.items-werk').length > 0 ? 'items-werk' : ($ ('.items-portfolio').length > 0 ? 'items-portfolio' : ($ ('.items-case').length > 0 ? 'items-case' : (url.length == 3 && url [2] == 'over-ons' ? 'over-ons' : 'all')))) + '&lang=' + lang,		
    	cache: false,
    	success: function (html) {
    	   
           $ ('#container').html (html);
           //Cufon.replace('h3 span');
           //$container.isotope('destroy');
           /*$container = $('#container');*/ 
           $container = $('#container')
        		, incr                  = 0
                , columnWidth           = 296
                , animationDuration     = 800
                , activeVideo			= false
                , shiftNav 				= false;
                
           $container.isotope({
                itemSelector : '.element',
                masonry: {columnWidth:232},
        		//fitRows: {columnWidth: 306},
                //layoutMode : 'masonry', 
                //animationOptions        : { duration: animationDuration },
                //itemPositionDataEnabled : true,
                masonryHorizontal : {
                rowHeight: 232
                },
                cellsByRow : {
                columnWidth : 464,
                rowHeight : 464
                },
                cellsByColumn : {
                columnWidth : 464,
                rowHeight : 464
                },
                sortBy: 'order',
                sortAscending : false,
                getSortData: {
                  
                  order : function( $elem ) {
                      return parseInt($elem.attr('data-order'));
                    },    
                  symbol : function( $elem ) {
                      return $elem.attr('data-symbol');
                    },
                    category : function( $elem ) {
                      return $elem.attr('data-category');
                    }
        
                }
                
            });	
            
            
            
            $ ('#options .option-set .selected').removeClass ('selected');
            
           
            
            $.openItem($container);
            $.initNav($container); 
            $.screenScroll();
            $.bookmarked();
           
            $ ('.case-default .lines,.portfolio-default .lines').mouseover (function (){
                $ (this).prev ().animate ({opacity:1}, 500);
                $ (this).animate ({opacity:0}, 500);
            });
            
            $ ('.case-default .lines,.portfolio-default .lines').mouseout (function (){
                $ (this).prev ().animate ({opacity:0.35}, 500);
                $ (this).animate ({opacity:1}, 500);
            });
            
            //Cufon.replace('h3 span');
    	}		
    });
    })
    
    //if ($ ('#container').length > 0)
        //$ ('.lang #default').trigger ('click');
    
    
    $ ('.submenu .klanten, .submenu .klanten-items ul').mouseover (function (){
        $ ('.submenu .klanten-items ul').css ('display', 'block');
    });
    
    $ ('.submenu .klanten, .submenu .klanten-items ul').mouseout (function (){
        $ ('.submenu .klanten-items ul').css ('display', 'none');
    });
    
    $ ('#portfolio .page .werk-image').click (function (){
        if ($ (this).prev ().attr ('id') == 'video' || $ (this).prev ().attr ('id') == 'video1')
        {
            $ (this).css ('display', 'none');
            $ (this).prev ().css ('display', 'block');
            var vid = document.getElementById($ (this).prev ().attr ('id'));
            vid.play(); 
        }    
    });
    
    $ ('#over-ons .page .image').click (function (){
        if ($ (this).prev ().attr ('id') == 'video')
        {
            $ (this).css ('display', 'none');
            $ ('video').css ('display', 'block');
            var vid = document.getElementById('video');
            vid.play(); 
        }    
    });
                
});

(function($){ 
jQuery.mlp = {x:0,y:0}; // Mouse Last Position
$(document).mousemove(function(e){
    jQuery.mlp = {x:e.pageX,y:e.pageY}
});
function notNans(value){
    if(isNaN(value)){
        return 0;
    } else {
        return value
    }
}
$.fn.ismouseover = function(overThis) {  
    var result;
    this.eq(0).each(function() {  
            var offSet = $(this).offset();
            var w = Number($(this).width())
            + notNans(Number($(this).css("padding-left").replace("px","")))
            + notNans(Number($(this).css("padding-right").replace("px",""))) 
            + notNans(Number($(this).css("border-right-width").replace("px","")))
            + notNans(Number($(this).css("border-left-width").replace("px",""))) ;
            var h = Number($(this).height()) 
            + notNans(Number($(this).css("padding-top").replace("px",""))) 
            + notNans(Number($(this).css("padding-bottom").replace("px","")))
            + notNans(Number($(this).css("border-top-width").replace("px","")))
            + notNans(Number($(this).css("border-bottom-width").replace("px","")));
            if(offSet.left<jQuery.mlp.x && offSet.left + w > jQuery.mlp.x
             && offSet.top<jQuery.mlp.y &&  offSet.top + h > jQuery.mlp.y)
            {
                result = true;
            } else {
                result = false;
            }
    });  
    return result;
    };  
})(jQuery); 


