﻿
jQuery.cookie = function (name, value, options) { if (typeof value != 'undefined') { options = options || {}; if (value === null) { value = ''; options = $.extend({}, options); options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); } var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } };


/*!
 * ContentHover jQuery plugin v0.1
 * http://www.backslash.gr/demos/contenthover-jquery-plugin/
 *
 * Copyright 2011 by Nikos Tsaganos
 * http://www.backslash.gr/
 */
(function ($) {
    var methods = {
        init: function (options) {
            var defaults = {
                data_selector: '.contenthover',	// The selector for the element that will be the content of the overlay element to show on hover
                width: 0,			// Set to 0 to let the plugin figure it out
                height: 0,			// Set to 0 to let the plugin figure it out
                overlay_width: 0,		// The overlay element's width. Set to 0 to use the same as 'width'
                overlay_height: 0,		// The overlay element's height. Set to 0 to use the same as 'height'
                overlay_x_position: 'center',	// [center, left, right] The position of the overlay horizontally (if overlay_width is different from width)
                overlay_y_position: 'bottom',	// [center, top, bottom] The position of the overlay vertically (if overlay_width is different from width)
                overlay_background: '',		// The css background of the overlay element
                overlay_opacity: 1,		// [0-1] The opacity of the overlay element
                effect: 'fade', 		// [fade, slide, show] The effect to use
                fade_speed: 400, 		// Effect ducation for the 'fade' effect only
                slide_speed: 400, 		// Effect ducation for the 'slide' effect only
                slide_direction: 'bottom',	// [top, bottom, right, left] From which direction should the overlay apear, for the slide effect only
                zindex: 2,			// The base z-index value
                wrapper_class: 'ch_wrapper', 	// CSS class to add to the wrapper
                normal_class: 'ch_normal',  	// CSS class to add to the 'normal' element
                hover_class: 'ch_hover',  	// CSS class to add to the 'hover' element
                onshow: function () { }, 		// Callback function when the 'hover' element is shown
                onhide: function () { } 		// Callback function when the 'hover' element is hidden
            },
			settings = $.extend({}, defaults, options);

            return this.each(function () {
                var $this = $(this),
					w = $this.width() ? $this.width() : settings.width,
					h = $this.height() ? $this.height() : settings.height,
					overlay_w = settings.overlay_width ? settings.overlay_width : w,
					overlay_h = settings.overlay_height ? settings.overlay_height : h,
					$data = $this.next(settings.data_selector);

                if ($data.length) {

                    $data.hide();

                    var $ch_wrapper = $('<div>').addClass('ch_element').addClass(settings.wrapper_class).css({ 'width': w, 'height': h, 'position': 'relative', 'overflow': 'hidden' }).insertAfter($this);

                    var $ch_normal = $('<div>').addClass(settings.normal_class).css({ 'width': w, 'height': h, 'position': 'absolute', 'z-index': settings.zindex }).appendTo($ch_wrapper);
                    $this.clone().appendTo($ch_normal);
                    $this.hide();

                    var $ch_hover = $('<div>').addClass(settings.hover_class).css({ 'width': overlay_w, 'height': overlay_h, 'position': 'absolute', 'z-index': settings.zindex - 1 }).appendTo($ch_wrapper);
                    $data.clone().show().appendTo($ch_hover);

                    var ch_hover_css = {};

                    if (settings.overlay_background) {
                        ch_hover_css.background = settings.overlay_background;
                    }
                    if (settings.overlay_opacity < 1) {
                        ch_hover_css.opacity = settings.overlay_opacity;
                    }


                    if (settings.overlay_x_position == 'left') {
                        ch_hover_css.left = 0;
                    } else if (settings.overlay_x_position == 'right') {
                        ch_hover_css.left = (w - overlay_w) + 'px';
                    } else {
                        ch_hover_css.left = (w / 2 - overlay_w / 2) + 'px';
                    }


                    if (settings.overlay_y_position == 'top') {
                        ch_hover_css.top = 0;
                    } else if (settings.overlay_y_position == 'bottom') {
                        ch_hover_css.top = (h - overlay_h) + 'px';
                    } else {
                        ch_hover_css.top = (h / 2 - overlay_h / 2) + 'px';
                    }

                    $ch_hover.css(ch_hover_css);

                    // slide effect
                    if (settings.effect == 'slide') {

                        var initial_css = {};

                        if (settings.slide_direction == 'top') {
                            initial_css = { top: ('-' + overlay_h + 'px') };
                        }
                        if (settings.slide_direction == 'bottom') {
                            initial_css = { top: h + 'px' };
                        }
                        if (settings.slide_direction == 'left') {
                            initial_css = { left: ('-' + overlay_w + 'px') };
                        }
                        if (settings.slide_direction == 'right') {
                            initial_css = { left: w + 'px' };
                        }

                        $ch_hover.css('z-index', settings.zindex + 1).css(initial_css);
                        $ch_wrapper.hover(function () {
                            $ch_hover.stop(true, true).animate({ 'top': ch_hover_css.top, 'left': ch_hover_css.left }, settings.slide_speed, settings.onshow());
                        }, function () {
                            $ch_hover.stop(true, true).animate(initial_css, settings.slide_speed, settings.onhide());
                        });


                        // fade effect
                    } else if (settings.effect == 'fade') {

                        $ch_hover.css('z-index', settings.zindex + 1).hide();
                        $ch_wrapper.hover(function () {
                            $ch_hover.stop(true, true).fadeIn(settings.fade_speed, settings.onshow());
                        }, function () {
                            $ch_hover.stop(true, true).fadeOut(settings.fade_speed, settings.onhide());
                        });

                        // just show/hide
                    } else {
                        $ch_hover.css('z-index', settings.zindex + 1).hide();
                        $ch_wrapper.hover(function () {
                            $ch_hover.show(0, settings.onshow());
                        }, function () {
                            $ch_hover.hide(0, settings.onhide());
                        });
                    }
                }
            });
        },

        stop: function () {
            return this.each(function () {
                var $this = $(this),
					$data = $this.next('.ch_element');

                $this.show();
                $data.remove();
                $this.unbind('.contenthover');
            });
        },

        destroy: function () {
            return this.each(function () {
                $(this).show();
                $('.ch_element').remove();
                $(window).unbind('.contenthover');
            });
        }
    };

    $.fn.contenthover = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist in contentHover plugin.');
        }
    };





})(jQuery);




function getInternetExplorerVersion() {

    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {

        var ua = navigator.userAgent;

        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null)

            rv = parseFloat(RegExp.$1);

    }

    return rv;

}

function checkVersion() {
    var msg = "You're not using Windows Internet Explorer.";
    var ver = getInternetExplorerVersion();
    if (ver > -1) {
        if (ver >= 8.0)
            msg = ""
        else
            $('.iewarning').show();
    }
}



$(function () {

    checkVersion();

    if ($('#numperpage').length) {
        $('#numperpage').val(numPerPage);
    }

    if ($('#restocknumperpage').length)
    {
        $('#restocknumperpage').val(numPerPageRestock);
    }

    $(".trigger").click(function () {
        $(".panel").toggle("fast");
        $(this).toggleClass("active");
        return false;
    });

    $('.myimage').contenthover({
        overlay_width: 200,
        overlay_height: 150,
        effect: 'slide',
        slide_direction: 'right',
        overlay_x_position: 'right',
        overlay_y_position: 'center',
        overlay_background: '#000',
        overlay_opacity: 0.8
    });

    if($('.carousel').length >0 ){
            $('.carousel').carousel();
    }

    $('#no-of-items-in-cart-display').html($('#incart').val());
    $('#no-of-items-in-cart-display-mobile').html($('#incart').val());
    $('#total-cost-of-cart').html($('#cartcost').val().toString("n2"));
$('#cc').hide();
$('#pp').hide();
//$('#credit-card-select').click(function() {
//   $('#pp').show();
//   $('#cc').hide();
//});

//$('#paypal-select').click(function() {
//        $('#cc').show();
//        $('#pp').hide();
//});

$('.navbar .dropdown').click(function() {
    $('.dropdown-menu', this).slideToggle(250);
});

var incrementalSearchCount = 0;
$("#keyword").on('input', function () {
    previewSearch(false);
});

    $("#keyword-mobile").on('input', function () {
        previewSearch(true);
    });

    $('#searchtype')
        .on('change',
            function() {
                previewSearch(false);
            }
    );

    $('#searchtype-mobile')
        .on('change',
            function () {
                previewSearch(true);
            }
        );

    function previewSearch(blnMobile) {
        var strKeywordID = '#keyword';
        var strSearchTypeID = '#searchtype';
        var strSearchPreviewTableID = '#searchpreviewtable';

        if (blnMobile) {
            strKeywordID = '#keyword-mobile';
            strSearchTypeID = '#searchtype-mobile';
            strSearchPreviewTableID = '#searchpreviewtable-mobile';
        }

    incrementalSearchCount++;
    $.ajax({
        type: "POST",
        url: "/ajaxcontroller/ajaxhandler.aspx",
        data: { functionname: "searchpreview", keyword: $(strKeywordID).val(), searchtype: $(strSearchTypeID + ' option').filter(":selected").val(), counter: incrementalSearchCount }
    })
        .done(function (msg) {
            if (msg) {
                var firstLineEnd = msg.indexOf("\n");
                var returnedCounterStr = msg.substr(0, firstLineEnd);
                var returnedCounter = Number(returnedCounterStr);
                if (returnedCounter === incrementalSearchCount) {
                    var lines = msg.substring(firstLineEnd + 1);
                    //$('.hideme').hide();
                    $(strSearchPreviewTableID).html(lines);
                }
            }
        });
}


 $("#search-btn").click(function (event) {

        $.ajax({
            type: "GET",
            url: "/ajaxcontroller/ajax-search.aspx",
            data: { functionname: "search", keyword: $('#keyword').val(), searchtype: $('#searchtype option').filter(":selected").val() }
        })
        .done(function (msg) {
            $('.hideme').hide();
            $('.search-response').html(msg);
        });

 });

    $("#search-btn-mobile").click(function (event) {

        $.ajax({
            type: "GET",
            url: "/ajaxcontroller/ajax-search.aspx",
            data: { functionname: "search", keyword: $('#keyword-mobile').val(), searchtype: $('#searchtype-mobile option').filter(":selected").val() }
        })
            .done(function (msg) {
                $('.hideme').hide();
                $('.search-response').html(msg);
            });

    });

//$(".remove-cart").click(function (event) {
//    if(event.target.id){
//        $.ajax({
//            type: "GET",
//            url: "/ajaxcontroller/ajaxhandler.aspx",
//            data: { functionname: "delitem", itemid: event.target.id}
//        })
//        .done(function (msg) {
//            $('#row-' + event.target.id).hide();
//        });
//    } else {
//        alert('no id');
//    }
//});

$(".addtocart").click(function (event) {
    if(event.target.id){
        $.ajax({
            type: "GET",
            url: "/ajaxcontroller/ajaxhandler.aspx",
            data: { functionname: "additem", itemid: event.target.id}
        })
        .done(function (msg) {
            var text = $('#' + event.target.id).data("ts-text");
            $('#poptext').html("<h3>Added to your cart : </h3>" + text);
            $('#incart').val(parseInt($('#incart').val()) + 1);
            $('#no-of-items-in-cart-display').html($('#incart').val());
            $('#no-of-items-in-cart-display-mobile').html($('#incart').val());
            $('#cartcost').val(parseFloat($('#cartcost').val()) + itemPrice);
            $('#total-cost-of-cart').html($('#cartcost').val().toString("n2"));
        });
    } else {
        alert('no id');
    }
});

    $('#numperpage').change(function() {
        var numPerPage = $('#numperpage').val();
        window.location.replace("index.aspx?numperpage=" + numPerPage);
    });

    $('#restocknumperpage').change(function ()
    {
        var numPerPageRestock = $('#restocknumperpage').val();
        window.location.replace("index.aspx?numperpagerestock=" + numPerPageRestock);
    });


// Drop down formatter
//$('#searchtype').selectpicker({});
//$('.searchtype').selectpicker({});

});


function playpop(itemId, title, artist, label, file, cover, buyLink, waveform, viewLink) {
    var newWin = window.open('/mediaplayer/MiniPlayer.aspx', "JSSite", "width=900,height=40,resizable=no,scrollbars=no,status=yes");
    var track = [{ 'title': title, 'artist': artist, 'label': label, 'file': file, 'buyLink': buyLink, 'itemId': itemId, 'cover': cover, 'waveform': waveform, 'viewLink': viewLink }];
    setCookie('plate_playlist', JSON.stringify(track), 7);
    $.cookie('plate_playlist', JSON.stringify(track), { expires: 7, path: '/' });

}


function play(itemId, title, artist, label, file, cover, buyLink, waveform, viewLink) {

    if (parent.$('.demoPlate').size() == 0) {
        try {
            var track = [{ 'title': title, 'artist': artist, 'label': label, 'file': file, 'buyLink': buyLink, 'itemId': itemId, 'cover': cover, 'waveform': waveform, 'viewLink': viewLink }];
            var jTrack = JSON.stringify(track);
            //alert("play" + jTrack + ")");
            setCookie('plate_playlist', jTrack, 7);
            $.cookie('plate_playlist', jTrack, { expires: 7, path: '/' });
        } catch (e) { }
        location.href = getMediaPlayerAddress();
    } else {
        parent.$('.demoPlate').data('plate').addTrack(itemId, title, artist, label, file, cover, buyLink, 0, waveform, viewLink);
    }
}

function getMediaPlayerAddress() {
    var url = '/mediaplayer/media-player.aspx';

    if (typeof searchKeyword != 'undefined' && searchKeyword) {
        url = url + '?searchkeyword=' + searchKeyword;
    }

    return url;
}

function setCookie(a, d, b) {
    var e = new Date();
    e.setDate(e.getDate() + b);
    var c = escape(d) + ((b == null) ? "" : "; expires=" + e.toUTCString());
    document.cookie = a + "=" + c
}

function addToPlayList(itemId, title, artist, label, file, cover, buyLink, waveform, viewLink) {
    if (parent.$('.demoPlate').size() == 0) {
        var track = [{ 'title': title, 'artist': artist, 'label': label, 'file': file, 'buyLink': buyLink, 'itemId': itemId, 'cover': cover, 'waveform': waveform, 'viewLink': viewLink }];
        var jTrack = JSON.stringify(track);
        //alert("addToPlayList" + jTrack + ")");
        setCookie('plate_playlist', jTrack, 7);
        $.cookie('plate_playlist', jTrack, { expires: 7, path: '/' });
        location.href = getMediaPlayerAddress();
    } else {
        parent.$('.demoPlate').data('plate').addTrack(itemId, title, artist, label, file, cover, buyLink, 1, waveform, viewLink);
    }
}

function addToCue(itemId, title, artist, label, file, cover, buyLink, waveform, viewLink) {
    if (parent.$('.demoPlate').size() == 0) {
        var track = [{ 'title': title, 'artist': artist, 'label': label, 'file': file, 'buyLink': buyLink, 'itemId': itemId, 'cover': cover, 'waveform': waveform, 'viewLink': viewLink }];
        var jTrack = JSON.stringify(track);
        //alert("addToCue" + jTrack + ")");
        setCookie('plate_playlist', jTrack, 7);
        $.cookie('plate_playlist', jTrack, { expires: 7, path: '/' });
        location.href = getMediaPlayerAddress();
    } else {
        //alert("addToCue2(" + title + "," + artist + "," + label + ")");
        parent.$('.demoPlate').data('plate').addTrack(itemId, title, artist, label, file, cover, buyLink, 1, waveform, viewLink);
    }
}









