
var objIvTT = new ivTT('img/', 'layer', '#itemList');

$(document).ready(function(){

	window.setTimeout("runOnLoad();", 50);

});


function runOnLoad () {
    
    $('.itemDetail').addClass('hidden');
    $('.itemList').removeClass('hidden');

    $('#itemList').isotope({
        layoutMode: 'fitRows',
        itemSelector: '.itemList',
        itemPositionDataEnabled: true,
        animationEngine : 'best-available',
        getSortData : {
            id: function ( $elem ) {
                return $elem.attr('id');
            }
        }
    });

    objIvTT.ivTT_init();


   
	$('a.lightbox').lightbox();
    
	$(".mp3").jmp3({
		backcolor: "608dec",
		//forecolor: "608dec",
		//width: 200,
		//showdownload: "true",
		showfilename: "false"
	});
    
    $('a[title = "lovecounter"]').each(function(i){
        
        var arr1 = $(this).html().split(' ');
        var arr2 = arr1[0].split('.');
        var arr3 = arr1[1].split(':');
        
        console.log (parseInt(arr2[2], 10));
        
        var objDate = new Date(parseInt(arr2[2], 10), parseInt(arr2[1], 10) -1, parseInt(arr2[0], 10), parseInt(arr3[0], 10), parseInt(arr3[1], 10), parseInt(arr3[2], 10));
        
        $(this).before('<div id="countdown_' + i + '" class="countdown"></div>');
        $(this).remove();
        
        $('#countdown_' + i).countdown({until: objDate, format: 'ODHMS'});
        $('#countdown_' + i).countdown($.countdown.regional['de']); 
            
        
    });
    
}


function loveCounter () {
    
    
    
}



function switchItem (strDirection, intCurrentItemId) {
    
    // define sorted array
    var arrItems = new Array();
    
    // loop all items
    $('#itemList .itemList').each(function(){
        // check if the item is not hidden
        if (!$(this).hasClass('isotope-hidden')) {
            // get current item position (x/y)
            var position = $(this).data('isotope-item-position');
            // calculate sorting by position to get the displayed order (not the DOM order, this would be wrong!)
            var sorting = (position.y * 1000) + position.x;
            // create object to hold item data
            var objItem = {
                id: $(this).attr('id').substr(5),
                sort: sorting
            };
            // check if the sorted array has at least one entry
            if (arrItems.length == 0) {
                // if not, simply push that item
                arrItems.push(objItem);
            } else {
                // if yes, loop the sorted array
                // define a var to hold if the new object was pushed while looped
                var boolIsSpliced = false;
                // loop
                for (var i = 0; i < arrItems.length; i++) {
                    // check if the sort data of the single object into the sorted array is greater to or equal to the current sorting
                    if (arrItems[i].sort >= sorting) {
                        // if yes, insert the item in the position before the current looped sorted array item
                        arrItems.splice(i, 0, objItem);
                        // remember that this item was inserted
                        boolIsSpliced = true;
                        // if it was inserted, stop the loop
                        break;
                    }
                }
                // check if the item were inserted to the sorted array while looped
                if (!boolIsSpliced) {
                    // if not, push
                    arrItems.push(objItem);
                }
            }
        }
    });
    
    // loop sorted items
    for (var i = 0; i < arrItems.length; i++) {
        // look for the given id
        if (arrItems[i].id == intCurrentItemId) {
            // if the id was found, decide by direction
            if (strDirection == 'next') {
                if (i < arrItems.length - 1) {
                    // if next was clicked and the sorted array is not at the end - load the next item of the array
                    $.nyroModalManual({
                        url: '#details_' + arrItems[i+1].id
                    });
                } else {
                    // if next was clicked and the sorted array is at the end - load the first item of the array
                    $.nyroModalManual({
                        url: '#details_' + arrItems[0].id
                    });
                }
            } else {
                if (i > 0) {
                    // if prev was clicked and the sorted array is not at the beginning - load the prev item of the array
                    $.nyroModalManual({
                        url: '#details_' + arrItems[i-1].id
                    });
                } else {
                    // if prev was clicked and the sorted array is at the beginning - load the last item of the array
                    $.nyroModalManual({
                        url: '#details_' + arrItems[arrItems.length-1].id
                    });
                }
            }
        }
    }
    
}



function filterContent (strFilter) {
    
    $('#itemList').isotope({ filter: strFilter });
    return false;
    
}



function sortContent (strSortBy) {
    
    $('#itemList').isotope({ 
        sortBy : strSortBy,
        sortAscending : false
    });
    return false;

}


    
// fix nyroModal dimensions
function fixNyroModalDimensions () {
    
    if ($.browser.msie && (parseInt($.browser.version) == 6 || parseInt($.browser.version) == 7)) {
        if (typeof $.nyroModalSettings == 'function') {
            $.nyroModalSettings({
                endShowContent: function() { 
                    if ($('#nyroModalContent').children('div.contentBlockL') != undefined && $('#nyroModalContent').children('div.contentBlockL') != null) {
                        var outerWidth = $('#nyroModalContent').children('div.contentBlockL').outerWidth(true);
                        var outerHeight = $('#nyroModalContent').children('div.contentBlockL').outerHeight(true);
                        $.nyroModalSettings({
                            width: outerWidth,
                            height: outerHeight
                        });
                    }
                    $('#nyroModalFull').click(function(event){
                        event.stopPropagation();
                    });
                }
            });
        }
    } else {    
        if (typeof $.nyroModalSettings == 'function') {
            $.nyroModalSettings({
                endShowContent: function() { 
                    $('#nyroModalFull').click(function(event){
                        event.stopPropagation();
                    });   
                }
            });
        }
    }
}


/*

    $.nyroModalManual({
      url: strHref + '&id=' + arrOfIds.join(','),
      title: strTitle
    });

    $.nyroModalManual({
        url: '#previewDiv',
        endShowContent: function() {
            setAdLinesPositions();
        }
    });



*/

    
