﻿/// <reference path="jquery-1.2.6-vsdoc.js" />
/// <reference path="jquery.blockUI.js" />

var winbuyer = function() {

function init() {
        $("a").filter(function() { if (this.hostname != location.hostname) $(this).attr('target', '_blank'); });
        $("#searchBox").get(0).focus();
        $("#cssmenu>li").hover(function ov() { ulHover(this); }, function ou() { ulOut(this); });
        //$("a").click(function eck(event) { elementClick(event, this); });
        //$("object#sundayskyDiv").click(function eck(event) { imageClick(event, this, "FlashVideo"); });
        //$(".sundaysky img").click(function eck(event) { imageClick(event, this, "VideoListButton"); });
        $(".sundaysky img").click(function cl() { handleVideoBtnClick(this); });
        initSundaySky();
    }

    function initSundaySky() {
        $.blockUI.defaults = {
            css: { position: 'fixed', top: '20%', left: '40%' },
            overlayCSS: { backgroundColor: '#000', opacity: '0.6' }
        };
    }

    function handleVideoBtnClick(obj) {
        var pid = $(obj).parents(".product").attr("pid");
        sundaySky.autoStart = true;
        sundaySky.flashvars = { displayclick: "play", dvg_real_estate_name: "popup" };
        sundaySky.realEstate = "search_page"; 
        sundaySky.create({ productId: pid }, { onObjectClick: videoClick });
        $.blockUI({
            message: $("#blockUI"),
            // styles for the message when blocking; if you wish to disable 
            // these and use an external stylesheet then do this in your code: 
            // $.blockUI.defaults.css = {}; 
            css: {
                width: '100%',
                top: '30%',
                left: '0px',
                textAlign: 'center',
                color: '#000',
                backgroundColor: 'transparent',
                cursor: 'default',
                position: 'fixed'
            },
            // styles for the overlay 
            overlayCSS: {
                backgroundColor: '#fff',
                opacity: 0.6,
                display: 'block'
            }
        });
    }

    function ulHover(obj) {
        $(obj).find("ul").show();
    }

    function ulOut(obj) {
        $("#cssmenu>li").find("ul").hide();
    }

    function videoClick(clickedObject) {
        if (clickedObject.actionName == "showStore") {
            var productTitle = $(".T1H2titleDiv>h1.t1h1").text();
            var destination = clickedObject.storeUrl;
            var url = location.href;
            var type = "SundaySkyVideo";
            $.post("/gHandlers/elementClicks.ashx", { destination: destination, url: url, hrefText: productTitle, type: type }); //logs to Site_Expansion.ClickLogs : DB.Table
            //            window.open(clickedObject.storeUrl);
            window.open(_root + "clickLog.aspx?url=" + escape(clickedObject.storeUrl)); //logs to campainslogs.StagingClicks : DB.Table
        }
    }

    function imageClick(e, elem, type) {
        //e.preventDefault();
        var url = location.href;
        var pName = $(elem).parents(".product").find(".pTitle a").text();
        var aHref = $(elem).parents(".product").find(".pTitle a").attr("href");
        var pId = $(elem).parents(".product").attr("pid");
        $.post("/gHandlers/elementClicks.ashx", { destination: aHref, url: url, hrefText: pName + " : " + pId, type: type });
    }

    function elementClick(e, elem) {
        //e.preventDefault();
        var destination = $(elem).attr("href");
        var hrefText = $(elem).text();
        var url = location.href;
        var type = $(elem).attr("type");
        $.post("/gHandlers/elementClicks.ashx", { destination: destination, url: url, hrefText: hrefText, type: type });
    }
    $(document).ready(init);

    return { storeHasBeenClicked: videoClick }
} ();
