//jQuery ready function when DOM is loaded

$(document).ready(function()
{
    $.get(
        "/common/headline.html", {}, function(data)
        {
            $("#myajaxnews").append(data).find("ul").newsTicker();
        }
        )
    $.get(
        "/common/headline-test.html", {}, function(data)
        {
            $("#myajaxnews-test").append(data).find("ul").newsTicker();
        }
        )

    $(".products-quickview img").mouseover(function() {
        var Id = $(this).parent().attr("id");
        var hWrapper = $(this).parent().parent().parent().parent().parent().height();
        var hWindow = $(window).height();
        var hDiff = (hWindow - hWrapper)/2;
        $(".product-quickview-wrapper").each(function(){
            if($(this).css("display")=="block")
            {
                $(this).hide();
            }
        });
      
        $("#"+Id+"-container").css({
            "top":"18%",
            "left":"27.2%"
        }).fadeIn("slow");
    });

    $(".close-products-quickview").click(function() {
        $(this).parent().parent().parent().parent().parent().parent().fadeOut("slow");
    });

     //For streaming slider Stream
    $(".stream-link").click(function() {
         $('#streamingContainer').html("");
        var Mp3 = $(this).attr("title");        
        var flashVars = "mp3="+Mp3+".mp3&showstop=1&showvolume=1&autoplay=1";
        var streamPlayer = "<object id='streaming' type='application/x-shockwave-flash' data='player_mp3_maxi.swf' width='200' height='20'>";
            streamPlayer = streamPlayer+"<param name='wmode' value='transparent' />";
            streamPlayer = streamPlayer+"<param name='movie' value='player_mp3_maxi.swf' />";
            streamPlayer = streamPlayer+"<param id='FlashVars' name='FlashVars' value='"+flashVars+"' />";
            streamPlayer = streamPlayer+"</object>";
            
        // Check if container is visible
        if($('#streaming-container').css('display') == "block")
        {
             $("#streaming-container").fadeOut("slow");
        }        
        $("#streaming-container").css({
            "top":"40%",
            "left":"56%"
        }).fadeIn("slow",function(){          
            $('#streamingContainer').html(streamPlayer);
        });                      
    });
    function streamPlay() {
        document.getElementById("streaming").SetVariable("player:jsPlay", "");  // Play
    }

    function streamStop() {
            document.getElementById("streaming").SetVariable("player:jsStop", "");// Stop
        }
    //For streaming container Close
    $(".close-streaming").click(function() {       
       $("#streaming-container").fadeOut("slow",function(){
           streamStop();
           $('#streamingContainer').html("");
       });
    });
    //For streaming slider
    $('ul#streamslider li').css("display","block");
    $('#streamslider').anythingSlider({
        buildNavigation: false,
        autoPlay: false
    });
    //For streaming slider Next slide
    $(".right-tab .previous").click(function() {
        $('#streamslider').data('AnythingSlider').goBack();         // go back one slide
    });
    //For streaming slider Previous slide
    $(".right-tab .next").click(function() {
        $('#streamslider').data('AnythingSlider').goForward();      // go forward one slide
    });
    
    //For Over sleeper slider
     $('ul#oversleeperslider li').css("display","block");
    $('#oversleeperslider').anythingSlider({
        buildNavigation: false,
        autoPlay: false
    });
   //For Over sleeper Next slide
    $(".previous-clocky").click(function() {
        $('#oversleeperslider').data('AnythingSlider').goBack();         // go back one slide
    });
    //For Over sleeper Previous slide
    $(".next-clocky").click(function() {
        $('#oversleeperslider').data('AnythingSlider').goForward();      // go forward one slide
    });
    
    if($(".right-tab").length >0)
        {
            $(".right-tab .anythingControls").css("display","none");
            $(".right-tab span.back").css("display","none");
            $(".right-tab span.forward").css("display","none");
        }
    // For Product Page Slider
    //$('ul#productslider li').css("display","block");
    //$('#productslider').anythingSlider({
    //buildNavigation: false
    //});
    // $("#productThumbs a img").bind("click",function(){
    //        var slideNum = $(this).attr("class");
    //        $('#productslider').anythingSlider(slideNum);
    //    });

    $(".left-tab .tabs ul li").click(function(){
        var thisRef = $(this);
        if(thisRef.attr("id").length>0)
        {           
            $(".tab-wrapper").css("display","none");
            
            $(".left-tab .tabs ul li").each(function(){
                var liId = $(this).attr("id");
                if($(this).attr("id").length>0){
                    $(this).removeClass("tab-active").addClass("tab");
                    $(this).find("img").attr("src","/images/products/text-"+liId+".png");
                }
            });
            var linkId = thisRef.attr("id");
            thisRef.removeClass("tab").addClass("tab-active");
            thisRef.find("img").attr("src","/images/products/text-"+linkId+"-over.png");
            $("#"+linkId+"-container").css("display","block");
            if(linkId == "reviews")
            {
                activateReviewTab(1);
            }
        }
    });

    $(".review-link").click(function(){
        var pNum = $(this).attr("class");
        activateReviewTab(pNum.substr(12));
    });   

});

function addBagButton()
{
    var p = $(".addBagButton");
    var position = p.position();
    var cartht = $(".addToCartContainer").height()+5;
    $(".addToCartContainer").css("top",position.top-cartht).fadeIn("slow");
}

function addToCartSkip()
{
    $(".addToCartContainer").fadeOut("slow",function(){
        $(".addToCartChk").attr('checked', false);
        $(".addToCartText").attr("value","");
        // For Add To Cart Data
        formSubmit();
    });    
}

function addToCartShare()
{    
    // Open Facebook Share window
    if($("#addToCartFacebook").attr('checked')==true)
    {
        var href = $(location).attr('href');
        u=encodeURIComponent(href);
        t=encodeURIComponent($(".addToCartTitle").text());
        d=encodeURIComponent($(".addToCartText").attr("value"));
        window.open(
            'http://fb-share-control.com?u='+u+'&amp;t='+t+'&amp;d='+d,
            'sharer','toolbar=0,status=0,width=1028,height=588');
    }
    if($("#addToCartTwitter").attr('checked')==true)
    {
        window.open(
            'http://twitter.com/home?status='+$(".addToCartText").attr("value"),'newWin',
            'twitter','toolbar=0,status=0,width=550,height=400');
    }

    // For Add To Cart Data
    formSubmit();

    // Close Add To Cart POP UP
    $(".addToCartContainer").fadeOut("slow",function(){
        $(".addToCartChk").attr('checked', false);
        $(".addToCartText").attr("value","");
    });
}

function activateReviewTab(pageNum)
{
    $.ajax(
    {
        url: "/comments/index.php",
        type: "GET",     
        cache: false,
        data: "&comm_page="+pageNum,
        success : function(html){
            $("#reviews-container").html(html);
        }
    });
}

function submitComments()
{    
     $.ajax(
    {
        url: "/comments/comments_process.php",
        type: "POST",
        cache: false,
        data: $("#frmComments").serialize(),
        success : function(html){
            $("#reviews-container").html(html);
        }
    });
}

// Initialize the plugin with no custom options
$(window).load(function() {
    $("div#makeMeScrollable").smoothDivScroll({});
});
(function($){
    $.fn.extend({
        center: function () {
            return this.each(function() {
                var top = ($(window).height() - $(this).outerHeight()) / 2;
                var left = ($(window).width() - $(this).outerWidth()) / 2;
                $(this).css({
                    position:'absolute',
                    margin:0,
                    top: (top > 0 ? top : 0)+'px',
                    left: (left > 0 ? left : 0)+'px'
                });
            });
        }
    });
})(jQuery);

// Function for to load Flash on link click on Home Page
function loadFlash()
{
    $(".hflawrapper-clocky").flashembed("Tocky_revised.swf");
}
// Function for to load Flash on link click on Tocky Floatbox
function loadTockyFlash()
{
    $(".float-wrapper-Tocky-div").flashembed("/Tocky_revised.swf");
}
// Function for to load Flash on link click on Clocky Floatbox
function loadClockyFlash()
{
    $(".float-wrapper-Clocky-div").flashembed("/clocky_revised.swf");
}


