//redirect iPhone/iPod touch to html version
if ((navigator.userAgent.toLowerCase().indexOf('iphone') != -1) || (navigator.userAgent.toLowerCase().indexOf('ipod') != -1) || (navigator.userAgent.toLowerCase().indexOf('android') != -1)) {
    //document.location.href='http://www.createam.at/mobile/';  
}  

$(document).ready(function() {
/*    if(jQuery.browser.msie) {
        setTimeout("C.resize();", 10);
    } else {
        C.resize();
    }*/

	$(".bni").click(function(){
		HNO = $(this).find('.bnic:visible');
		$('.bnic').hide();
		HNO.show();		
		$(this).find('.bnic').toggle(100);
	}); 
    
    if (bIphone == 0) {
        setTimeout("C.init();", 500);
    }

    // Filter stuff
    $("#REF-filter").click(function() {
        $("#REF-filter").addClass("on");
        $("#REF-filter-data").css("top", $(this).parents(".subnav").height()).show();
    });
    
    $("#REF-filter-data div").live("click", function() {
        $("#REF-filter-data").hide();
        $("#REF-filter").removeClass("on");
    });
    
    $("#REF-filter-basic").click(function() {
        $("#REF-filter-basic").addClass("on");
        $("#REF-filter-basic-data").css("top", $(this).parents(".subnav").height()-18).show();
    });

    $("#REF-filter-basic-data div").live("click", function() {
        $("#REF-filter-basic-data").hide();
        $("#REF-filter-basic").removeClass("on");
    }); 
    
    $(".images a").fancybox();
    $(".fancybox a").fancybox();
    $("#fancy_overlay").css("height", $(window).height());
    
    $(".news-single-img a img").hide();
    $(".news-single-img a img:first").show();
    
    $(".jqfancybox").fancybox();
    $(".fancyvideo").fancybox({"hideOnContentClick": false});

    jsReady = true;
});

var C = {
    init: function() {
        C.resize();
        C.scaleAnimation();
    },
    
    resize: function() {
    	if (bIphone == 0) {
            var offset = 0;
            if ($("#topnav").parent().attr("id") == "main") {
                offset = $("#topnav").height() + 25;
            }
            var h = $(window).height() - 100 - $("#nav").height() - 25;
            $("#content, .jScrollPaneContainer").height(h - offset).width($(window).width() - 75);    
            $("#content").jScrollPane({showArrows: false, scrollbarWidth: 12, reinitialiseOnImageLoad: false});
        }
    },
    
    scaleAnimation: function() {
        $("#swf-ani").each(function() {
            var h = $(this).height();
            var parent = $(this).parent();
            var container = parent.parent().height();
            var content = parent.height();
            var newHeight = h - (content - container);
            if (newHeight < 150) {
                newHeight = 150;
            }
            
            if (h > newHeight) {
                var fact = newHeight / h;
                $(this).height(newHeight);
                $(this).width($(this).width() * fact);
                $("#content").jScrollPane({showArrows: false, scrollbarWidth: 12, reinitialiseOnImageLoad: false});
            }
        });
    },
    
    scale: function(height) {
        var h = parseInt(height);
        $("#nav").height(h);
        $("#main").css("top", (h + 20) + "px");
    },
    
    cursorFix: {
        footerObj: false,
        init: function() {
            C.cursorFix.footerObj = $("#footerobj").get(0);
            
            if (C.cursorFix.footerObj && typeof C.cursorFix.footerObj.setHand != "undefined") {
                $("a").hover(function() {
                    C.cursorFix.footerObj.setHand();
                }, function() {
                    C.cursorFix.footerObj.unsetHand();
                });
            }
        }
    }
};

function setApplication(id) {
    if (id.indexOf("http://") > -1) {
        document.location.href = id;    
    } else {
        var url = "http://" + document.location.host + "/" + id;
        if (id == "home") {
            url = "http://" + document.location.host + "/start/";
        }
        document.location.href = url;
    }
}
function setBrandNewPage(page) {
    $.get("/", {"eID": "ajax", "brandneu": page});
}

window.onresize = C.resize;

function ShowMore() {
    $("#morebutton").hide();
    $("#moretext").show();
    
    C.resize();
}

function bringBrandnewToFront() {
    $("#footer").css("zIndex", 50);
}

function sendBrandnewToBack() {
    $("#footer").css("zIndex", 10);
}

var jsReady = false;
function isReady() {
    return jsReady;
}
