// JavaScript Document

 
(function($) {
  

    
        
    
    

    $.fn.randomize = function(childElem) {
        return this.each(function() {
            var $this = $(this);
            var elems = $this.children(childElem);
      
            elems.sort(function() {
                return (Math.round(Math.random())-0.5);
            });  
 
            $this.empty();  
 
            for(var i=0; i < elems.length; i++)
                $this.append(elems[i]);      
 
        });    
    }
})(jQuery);

function testGal(){
    $("#testSlider li:first-child").clone().appendTo("#testSlider");
    numTest = $("#testSlider li").length;
    testI = 1;
    testW = 550;
    tmpX = 0;
    numSec = 5;
    pauseDur = 6000;
    twDur = 1875;
    easing = "easeOutQuad";
    $("#testSlider").randomize("li");
    timer = setTimeout("testIter()",pauseDur);
}

function testIter(){
    //alert("contact");
    if(testI >= numTest){
        tmpX = -550;
        $("#testSlider").css("left","0px");
        testI = 1;
    } else {
        tmpX = tmpX-testW;
    }
    newX = tmpX+"px";
    $("#testSlider").animate({
        "left":newX
    },twDur);
    testI++;
    timer = setTimeout("testIter()",pauseDur);
}

$(document).ready(function(){
    testGal();
    $("#nav li:last-child").mouseover(function(){
        $(this).css("background-color","#96b195");
        $("#nav ul").css("background-color","#96b195");
    });
	
    $("#nav li:last-child").mouseout(function(){
        $(this).css("background-color","#000");
        $("#nav ul").css("background-color","#000");
    });
	
    if($("#nav li:last-child").hasClass("selected")){
        $("#nav ul").css("background-color","#96b195");
    }
	
    $("body").append('<div id="fmg-float-img"><img class="fmg-float-img-loading" src="http://www.cochon555.com/2011/wp-content/themes/2011/image/lightbox-ico-loading.gif" /><img class="fmg-float-img-tag" src=""/><p class="fmg-description"></p></div>');
    // reveals bigger image when you pass the mouse over it
    $(".set a:has(img)").live("mouseover", function(){
        var src = $("img", this).attr("src");
        var title = $("img", this).attr("alt");
        var img = src.replace("_t", "_m");
        var url = img.replace("_s", "_m");
        $("#fmg-float-img").show()
        $("#fmg-float-img .fmg-description").hide()		
        $("#fmg-float-img .fmg-float-img-loading").show()
        $("#fmg-float-img .fmg-float-img-tag").hide().attr("src",url).load(function() {
            $("#fmg-float-img .fmg-float-img-loading").hide()
            $(".fmg-float-img-tag").fadeIn(500, function(){
                //console.log(title)
  				
                });
            $("#fmg-float-img .fmg-description").text(title).slideDown()
        })
    });
	
    $(".set a:has(img)").live("mouseout", function(){
        $("#fmg-float-img").hide()
        $("#fmg-float-img .fmg-description").hide()		
        $("#fmg-float-img .fmg-float-img-loading").hide()
    });
    $('.set').live("mousemove",function(e) {
        var pos = $(this).position()
        var h = $("#fmg-float-img").height() 
        $("#fmg-float-img").css({
            top:e.pageY-40, 
            left:e.pageX+20
        })
    //console.log((e.pageY - pos.top) +", "+(e.pageX - pos.left))
    });
});

$("#faqPop").ready(function(){
    $("#faqPop").dialog({
        bgiframe: false,
        autoOpen: false,
        height: 450,
        width: 450,
        resizable: false,
        modal: true
    });
    $("#faqPop .popContent").load('http://cochon555.com/2012/other/faqs/');
});

$("#privacyPop").ready(function(){
    $("#privacyPop").dialog({
        bgiframe: false,
        autoOpen: false,
        height: 500,
        width: 480,
        resizable: false,
        modal: true
    });
    $("#privacyPop .popContent").load('http://cochon555.com/2012/other/privacy/');
});

function openFaq(){
    $("#faqPop").dialog('open');
}

function openPrivacy(){
    $("#privacyPop").dialog('open');
}

$(function() {
    // Use this example, or...
    $('.set a').lightBox({
        fixedNavigation:true
    }); // Select all links that contains lightbox in the attribute rel
});




