
var getIdFromHref = function(href) {
    if (/.*#[\w\-]+$/.test(href)) {
        return href.replace(/.*#([\w\-]+)$/, '$1');
    }
    return false;
}


var getLinkTooltipContent = function(href) {
    var id = getIdFromHref(href);
    if (id) {
        var node = document.getElementById(id);
        //return node.innerHTML;
        return node;
    }
    return false;
}

var clickHighslideCentered = function() {
    var id = getIdFromHref(this.href);
    if (id) {
        var node = document.getElementById(id);
        if (node) {
            if (!document.getElementById(id + '-content')) {
                $('body').append('<div class="hidden highslide-html-content" id="' + id + '-content"><div class="highslide-header"><ul><li class="highslide-move"><a href="#" onclick="return false">Move</a></li><li class="highslide-close"><a href="#" onclick="return hs.close(this)">Close</a></li></ul></div><div class="highslide-body"></div><div class="highslide-footer"><div><span class="highslide-resize" title="Resize"><span></span></span></div></div></div>');
                $('.highslide-body', '#' + id + '-content').append($(node).removeClass('hidden'));
            }
            //hs.htmlExpand(this, { contentId: id + '-content', align: 'center' } );
        }
    }
    //return hs.htmlExpand(this, { contentId: 'highslide-html' } );
    return false;
}

var clickSelectControl = function() {
    return false;
}

var openSelectControl = function() {
    var id = getIdFromHref(this.href);
    if (id) {
        var node = document.getElementById(id);
        $(node).slideDown('fast');
    }
    return false;
}

var closeSelectControl = function() {
    var id = getIdFromHref(this.href);
    if (id) {
        var node = document.getElementById(id);
        $(node).slideUp('fast');
    }
    return false;
}

var setHoverEffect = function(context) {
    context = context || document;
    $('a.ui-state-default', context).add('input.ui-state-default', context).add('span.ui-state-default', context).hover(function(){
        $(this).addClass('ui-state-hover');
    },function(){
        $(this).removeClass('ui-state-hover');
    });
}

jQuery(document).ready(function($){
    
    // Hide/Show Review Form
    //$('#content_block_discussion .subheader:first').click(clickHighslideCentered);
    
    //$('a.highslide').add('a.highslide-banner').click(clickHighslideAuto);
    
    //$('a.highslide-center').click(clickHighslideCentered);
    /*$('a.highslide').add('a.highslide-banner').simpletip({
        //persistent: true,
        //position: ['0', '12'],
        //focus: focus,
        //label: 'label',
        content: '$(node).removeClass(hidden).html()'
    });*/
    //$('a.rs-select-control').toggle(openSelectControl, closeSelectControl);
    //$('a.rs-select-control').slideToggle('fast', clickSelectControl);
    
    //$('ul.cm-select-list a').addClass('ui-state-default');
    
    $.fn.qtip.styles.pophint = { // Last part is the name of the style
        //width: 200,
        //padding: 5,
        //background: '#A2D959',
        //color: 'black',
        //textAlign: 'center',
        border: {
            width: 5//,
            //radius: 5,
            //color: '#A2D959'
        },
        tip: false,
        //tip: 'topLeft',
        /*tip: { // Now an object instead of a string
            corner: 'topLeft', // We declare our corner within the object using the corner sub-option
            //color: '#6699CC',
            size: {
                x: 50, // Be careful that the x and y values refer to coordinates on screen, not height or width.
                y : 20 // Depending on which corner your tooltip is at, x and y could mean either height or width!
            }
        },*/
        name: 'light'
    };
    $('a.rs-pophint').each(function(){
        var content = getLinkTooltipContent(this.href);
        if (content) {
            $(this).qtip({
                content: $(content),
                show: 'click',
                position: {
                    corner: {
                        target: 'bottomMiddle',
                        tooltip: 'topMiddle'
                    }
                },
                style: 'pophint'
            });
        }
        $(this).click(function(){
            return false;
        });
    });
    
    $('a.rs-popmenu').each(function(){
        var content = getLinkTooltipContent(this.href);
        if (content) {
            $(this).parent().hover(function(){
                $(content).show('fast');
            }, function(){
                $(content).hide('fast');
            });
        }
        $(this).click(function(){
            return false;
        });
    });
    
    $('a.rs-popup').each(function(){
        if (!$('#rs_popup').length) {
            if (typeof document.body.style.maxHeight == 'undefined') {//if IE 6
                var trl_shadows = '<div class="w-shadow" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + images_dir + '/shadow_w.png, sizingMethod=scale);"></div><div class="e-shadow" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + images_dir + '/shadow_e.png, sizingMethod=scale);"></div><div class="nw-shadow" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + images_dir + '/shadow_nw.png, sizingMethod=scale);"></div><div class="ne-shadow" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + images_dir + '/shadow_ne.png, sizingMethod=scale);"></div><div class="sw-shadow" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + images_dir + '/shadow_sw.png, sizingMethod=scale);"></div><div class="se-shadow" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + images_dir + '/shadow_se.png, sizingMethod=scale);"></div><div class="n-shadow" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + images_dir + '/shadow_n.png, sizingMethod=scale);"></div>';
                var b_shadow = '<div class="s-shadow" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + images_dir + '/shadow_s.png, sizingMethod=scale);"></div>';
            } else {//all others
                var trl_shadows = '<div class="w-shadow"></div><div class="e-shadow"></div><div class="nw-shadow"></div><div class="ne-shadow"></div><div class="sw-shadow"></div><div class="se-shadow"></div><div class="n-shadow"></div>';
                var b_shadow = '<div class="s-shadow"></div>';
            }
            var html = '<div id="rs_overlay" class="hidden"></div><div id="rs_popup" class="hidden">'
                //+ '<div class="w-shadow"></div><div class="e-shadow"></div><div class="nw-shadow"></div><div class="ne-shadow"></div><div class="sw-shadow"></div><div class="se-shadow"></div><div class="n-shadow"></div>'
                + trl_shadows
                + '<div id="rs_popup_closer"><img alt="Close" title="Close" class="cm-notification-close" src="' + images_dir + '/icons/close_popupbox.png" /></div><div id="rs_popup_border"><div id="rs_popup_title" class="hidden"></div><div id="rs_popup_content"></div></div>'
                //+ '<div class="s-shadow"></div>'
                + b_shadow
                + '</div>';
            $('body').append(html);
            $('#rs_overlay').add('#rs_popup_closer img').click(function(){
                $('#rs_popup').hide();
                $('#rs_overlay').hide();
            });
        }
        $(this).click(function(){
            var content = getLinkTooltipContent(this.href);
            if (content) {
                if (this.title.length > 0) {
                    $('#rs_popup_title').html(this.title).show();
                } else {
                    $('#rs_popup_title').hide();
                }
                // move old content to prevent deleting
                var old = $('#rs_popup_content').children('div');
                if (old.length) {
                    $('body').append(old);
                }
                $('#rs_popup_content').html(content);
                $(content).removeClass('hidden');
                setHoverEffect(content);
                //$('#rs_popup_content').css({ height: $('#rs_popup_content').height() });
                $('#rs_overlay').height($('body').height()).show();
                var height = $('#rs_popup').css({ height: 'auto' }).height();
                $('#rs_popup').height(height).fadeIn('first');
                $('html, body').animate({
                    scrollTop: 0
                }, 500);
            }
            return false;
        });
        $('a.button-top').click(function(){
            $('html, body').animate({
                scrollTop: 0
            }, 500);
            return false;
        });
    });
    


    setHoverEffect();



});

/*$.bind("ajaxSuccess", function(){
    $('a.ui-state-default').hover(function(){
        $(this).addClass('ui-state-hover');
    },function(){
        $(this).removeClass('ui-state-hover');
    });
});
*/


/*
<div id="notification_6aa162302a2c5769f7a869578a149c85__5" class="product-notification-container cm-auto-hide" style="top: 391px;"><div class="w-shadow"></div><div class="e-shadow"></div><div class="nw-shadow"></div><div class="ne-shadow"></div><div class="sw-shadow"></div><div class="se-shadow"></div><div class="n-shadow"></div><div class="popupbox-closer"><img alt="Close" title="Close" class="cm-notification-close" src="/cs-carts/cs-cart.2.1.0/skins/rajasthani_store/customer/images/icons/close_popupbox.png"></div><div class="product-notification"><h1>Product was added to your cart</h1>

<div class="notification-body"><ul><li><a href="index.php?dispatch=products.view&amp;product_id=29778">Sky Blue Designer Style Embroidered Kurta 1</a></li><li><strong class="valign">1</strong>&nbsp;x&nbsp;<span class="none">Rs. </span><span class="none" id="sec_price_163659887">5,000</span></li></ul></div><div class="clear"><div class="float-left">
    
 

    <span class="button"><a class="cm-notification-close ">Continue shopping</a></span>

</div><div class="float-right">
        
 

    <span class="button-action"><a class="" href="index.php?dispatch=checkout.checkout">Checkout</a></span>

</div></div></div><div class="s-shadow"></div></div>
*/




