var application = application || {}

application.isIDevice = function () {
	return (
		(navigator.platform.indexOf("iPhone") != -1) ||
		(navigator.platform.indexOf("iPod") != -1) ||
		(navigator.platform.indexOf("iPad") != -1)
	);
}

application.scrollPageTo = function(num){
	$("html:not(:animated),body:not(:animated)").animate({
		scrollTop: num
	}, 500 );
}

application.openWindow = function (location, name, width, height, scrollbars) {
    scrollbars = scrollbars == true ? true : false;
    var argListString = "";
    var argListTemp = [];
    var argList = { "toolbar"   : 0,
                    "resizable" : 0,
                    "status"    : 0,
                    "location"  : 0,
                    "scrollbars": 0}

    if (scrollbars) 
    {
        argList.scrollbars = 1;
    }

    for (var key in argList) 
    {
        argListTemp.push(key + "=" + argList[key]);
    }

    argListString = argListTemp.join(", ");

    winPop = window.open(location, name, 'width=' + width + ', height=' + height + ', ' + argListString);
    winPop.focus();
}


$(function () {

    // nav
    //fixes a bug where menu isn't tall enough when you rollover it
    $('.tabs>li').bind("mouseover", function () {
        $("#nav").addClass("menu-hover");
    }).bind("mouseout", function () {
        $("#nav").removeClass("menu-hover");
    })
    if ($("div.pipe").length) {
        new sandstorm.PipeCircular($("div.pipe"), 5, $.browser.webkit, null, $('.find-your-juice .right-arrow'), $('.find-your-juice .left-arrow'));
    }


    //close buttons
    $("a.to-top").bind("click", function () {
        application.scrollPageTo(0);
        return false;
    })

    //input field for news section pagination
    $("#pagination-input").bind("keypress", function (e) {
        if (e.keyCode == 13) {
            document.location.href = '/fresh-news/all/' + $(this).attr('value'); 
        }
    });

    $("#where-to-buy").click(function (e) 
    {
        var url = $(this).attr("href");
        application.openWindow(url, "locator", 600, 454, false);
        return false;
    })

    $("#terms-of-use").click(function (e) {
        var url = $(this).attr("href");
        application.openWindow(url, "locator", 850, 450, true);
        return false;
    })

    $("#privacy-policy").click(function (e) {
        var url = $(this).attr("href");
        application.openWindow(url, "locator", 850, 450, true);
        return false;
    })

})


