jQuery(function () {

    jQuery("ul li:first-child").addClass('first');
    jQuery(".company ul li:last-child, .company .sidebar div:last-child, .company .c1 div:last-child, .company table tr:last-child, .secondary-navigation ul li:last-child").addClass('last');

    jQuery("#bill-analysis").tabs({
        selected: 0
    });

    jQuery("#product-details").tabs({
        selected: 0
    });

    jQuery("#ir-search").tabs({
        selected: 0
    });

    // TAB 2 PROMOS
    jQuery('.tab-2 .promo .inner, .promo a.close').hide();

    jQuery('.tab-2 .promo a.more').click(function (e) {
        e.preventDefault();
        jQuery('.tab-2 .promo .inner').slideToggle();
    });

    jQuery('.tab-2 .promo2 a.close').click(function (e) {
        e.preventDefault();
        jQuery('.tab-2 .promo2').slideUp();
    });


    jQuery('.tab-2 .promo2 .inner, .promo2 a.close2').hide();

    jQuery('.tab-2 .promo2 a.more2').click(function (e) {
        e.preventDefault();
        jQuery('.tab-2 .promo2 .inner').slideToggle();
    });

    jQuery('.tab-2 .promo2 a.close2').click(function (e) {
        e.preventDefault();
        jQuery('.tab-2 .promo2').slideUp();
    });

    // BUSINESS MORE INFO DIV
//    jQuery('.full-info, .close-info').hide();

//    jQuery('.more-info a').click(function (e) {
//        e.preventDefault();
//        jQuery('body.business .banners').hide();
//        jQuery('.close-info').show();
//        jQuery('.more-info').slideUp();
//        jQuery('.full-info').slideDown();
//    });

//    jQuery('.close-info a').click(function (e) {
//        e.preventDefault();
//        jQuery('body.business .banners').slideDown();
//        jQuery('.close-info').hide();
//        jQuery('.more-info').slideDown();
//        jQuery('.full-info').slideUp();
//    });

    jQuery('select#job-search').change(function () {
        // set the window's location property to the value of the option the user has selected
        window.location = jQuery(this).val();
    });

    // FAQ STYLE OPEN AND CLOSE
    jQuery(".toggle_container").hide();

    jQuery(".trigger").click(function (e) {
        e.preventDefault();
        jQuery(this).toggleClass("active").next().slideToggle("slow");
    });

});


function mailpage() {
    mail_str = "mailto:?subject=" + document.title; mail_str += "&body= " + location.href; location.href = mail_str;
}

function BAlign() {
    var Left = jQuery(".left").height();
    var Right = jQuery(".right").height();
    if (Left > Right) {
        jQuery(".right").height(Left);
        jQuery(".expand").height(Left);
    } else {
        jQuery(".left").height(Right);
        jQuery(".expand").height(Right);
    }
}

jQuery(window).load(function () { //start after HTML, images have loaded

    var InfiniteRotator =
    {
        init: function () {
            //initial fade-in time (in milliseconds)
            var initialFadeIn = 1000;

            //interval between items (in milliseconds)
            var itemInterval = 5000;

            //cross-fade time (in milliseconds)
            var fadeTime = 2000;

            //count number of items
            var numberOfItems = jQuery('.items').length;

            //set current item
            var currentItem = 0;

            //show first item
            jQuery('.items').eq(currentItem).fadeIn(initialFadeIn);

            //loop through the items
            var infiniteLoop = setInterval(function () {
                jQuery('.items').eq(currentItem).fadeOut(fadeTime);

                if (currentItem == numberOfItems - 1) {
                    currentItem = 0;
                } else {
                    currentItem++;
                }
                jQuery('.items').eq(currentItem).fadeIn(fadeTime);

            }, itemInterval);
        }
    };

    InfiniteRotator.init();

});


jQuery(document).ready(function () {
    jQuery(".slide1").click(function () {
        if (jQuery(".search-tools").height() == "143") {
            jQuery(".search-tools").animate({
                height: "40px"
            }, { queue: false, duration: 500
            });
            //jQuery(".jcarousel-skin-tango").hide("slow");
            jQuery(".jcarousel-skin-tango").hide();
            //jQuery(".search-tools").css("background-image", "url(images/bg_search_tools.png)");
            jQuery(".slide1").attr("src", "/Style%20Library/Resources/Images/arrow_box_closed.png");
        } else {
            jQuery(".search-tools").animate({
                height: "143px"
            }, { queue: false, duration: 500
            });
            //jQuery(".jcarousel-skin-tango").show("slow");
            jQuery(".jcarousel-skin-tango").show("slow");
            //jQuery(".search-tools").css("background-image", "url(images/bg_search_tools_icons-repeat.jpg)");
            jQuery(".slide1").attr("src", "/Style%20Library/Resources/Images/arrow_box_open.png");
        }
    });
});

jQuery(document).ready(function () {
    jQuery(".slide2").click(function () {
        if (jQuery(".quick-links-container").height() == "185") {
            jQuery(".quick-links-container").animate({
                height: "40px"
            }, { queue: false, duration: 500
            });
            jQuery(".slide2").attr("src", "/Style%20Library/Resources/Images/arrow_box_closed.png");
        } else {
            jQuery(".quick-links-container").animate({
                height: "185px"
            }, { queue: false, duration: 500
            });
            jQuery(".slide2").attr("src", "/Style%20Library/Resources/Images/arrow_box_open.png");
        }
    });
});

/*function mycarousel_initCallback(carousel){};
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
wrap: 'null',
initCallback: mycarousel_initCallback,
scroll: 5,
visible: 5
});
});*/

/*    jQuery(document).ready(function(){
jQuery('#mycarousel').bxSlider({
displaySlideQty: 5,
moveSlideQty: 5,
infiniteLoop: false,
hideControlOnEnd: true,
controls: true,
nextText: "",
prevText: "",
startingSlide: 0
});
});*/


jQuery(document).ready(function () {

    jQuery(function () {
        var step = 5;
        var current = 0;
        var maximum = jQuery('#my_carousel ul li').size();
        var visible = 5;
        var speed = 500;
        var liSize = 331;
        var carousel_height = 161;


        var ulSize = liSize * maximum;
        var divSize = liSize * visible;

        jQuery('#my_carousel ul').css("width", ulSize + "px").css("left", -(current * liSize)).css("position", "absolute");

        jQuery('#my_carousel').css("width", divSize + "px").css("height", carousel_height + "px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");

        jQuery('.btnnext').click(function () {
            if (current + step < 0 || current + step > maximum - visible) { return; }
            else {
                current = current + step;
                jQuery('#my_carousel ul').animate({ left: -(liSize * current) }, speed, null);
            }
            return false;
        });

        jQuery('.btnprev').click(function () {
            if (current - step < 0 || current - step > maximum - visible) { return; }
            else {
                current = current - step;
                jQuery('#my_carousel ul').animate({ left: -(liSize * current) }, speed, null);
            }
            return false;
        });
    });
});

/*Availability Tool*/
function SetDefault(element, txtstring) {
    if (document.getElementById(element).value == txtstring) {
        document.getElementById(element).value = '';
    }
    else if (document.getElementById(element).value == '') {
        document.getElementById(element).value = txtstring;
    }

}

// function to limit the field input to numbers only. And the decimal point if the input is supposed to be decimal
function AllowNumbersOnly(e, decimal) {

    var key;
    var keychar;
    if (window.event) {
        key = window.event.keyCode;
    }
    else if (e) {
        key = e.which;
    }
    else {
        return true;
    }
    keychar = String.fromCharCode(key);

    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) || (key == 46) || (key == 37) || (key == 39)) {
        return true;

    }

    else if (((key >= 48) && (key <= 57)) || ((key >= 96) && (key <= 105))) {
        return true;
    }

    else if (decimal && (keychar == ".")) {
        return true;
    }
    else
        return false;
}

jQuery.fn.AttachColorboxPopUp = function () {
    var element = jQuery(this[0]);
    if (element.is("a"))
        if (element.attr('href')) {
            var link = element.attr('href');
            if (link.toLowerCase().indexOf('/_layouts/click2call/click2call.aspx') !== -1) {
                element.colorbox({ iframe: true, innerWidth: 400, innerHeight: 420, returnFocus: false });
            }
        }
};


jQuery(document).ready(function () {
    jQuery("a").each(function () {
        jQuery(this).AttachColorboxPopUp();
    });
});


/***      Home Page Banners      ***/

function DisplayThumbnail() {
}

function InitiateHomepageBanners(bannerTransitionSpeed) {

    //var originalIFrameSource;
    //jQuery('iframe').each(function(index) {
    //	originalIFrameSource = jQuery(this).attr('src');
    //	jQuery(this).attr('src', originalIFrameSource);
    //  });


    jQuery('#bannerHome').before('<div id="bannerHomePagingLeft">&nbsp;&nbsp;&nbsp;&nbsp;</div><div id="bannerHomePaging" class="bannerHomePaging" onMouseOver="DisplayThumbnail(); return true">').cycle({
        fx: 'fade',
        speed: bannerTransitionSpeed,
        timeout: 3000,
        pager: '#bannerHomePaging',
        before: function () { if (window.console) console.log(this.src); }
    });


    jQuery('#bannerHome').after('<div id="bannerHomePagingRight">&nbsp;&nbsp;&nbsp;&nbsp;</div>');


    var pagingWidth = jQuery('#bannerHomePaging').width();

    jQuery('#bannerHomePagingRight').css({ left: pagingWidth + 30 });

    var elems = jQuery(".bubbleInfo").children(); // returns a nodeList
    if (elems.length == 0)
        return;

    var arr = jQuery.makeArray(elems);


    jQuery("#bannerHomePaging").children().each(function (index) {
        // options
        var distance = 10;
        var time = 250;
        var hideDelay = 500;

        var hideDelayTimer = null;
        // tracker
        var beingShown = false;
        var shown = false;

        var trigger = this; // jQuery('.trigger', this);
        var popUpName = '.bubbleInfoPopup' + index;
        //alert('popUpName=' + popUpName);
        // alert(trigger.position());

        //        if (trigger.length != 0) {
        //      var tempo = jQuery('#bannerHomePaging');
        //     if (tempo.length != 0) {

        //   alert(tempo.tagName);
        //  }
        //    elePosition = trigger.position();
        //   alert(elePosition.top );
        //compareLink.css({ top: elePosition.top + 22 });
        //}            
        //alert(trigger.tagName);
        //var popup = arr[index];
        //alert('index=' + index + 'popup.tagName=' + popup.tagName);
        //alert(popup.css);

        // popup.css('opacity', 0);

        var popup = jQuery(popUpName).css('opacity', 0);
        //alert(arr[index].tagName);
        // set the mouseover and mouseout on both element
        jQuery([trigger], arr[index]).mouseover(function () {
            // alert(trigger.tagName);
            // stops the hide event if we move from the trigger to the popup element
            if (hideDelayTimer) clearTimeout(hideDelayTimer);

            // don't trigger the animation again if we're being shown, or already visible
            if (beingShown || shown) {
                return;
            } else {
                beingShown = true;

                // reset position of popup box
                popup.css({
                    top: -115,
                    left: 30,
                    display: 'block' // brings the popup back in to view
                })

                // (we're using chaining on the popup) now animate it's opacity and position
		.animate({
		    top: '-=' + distance + 'px',
		    opacity: 1
		}, time, 'swing', function () {
		    // once the animation is complete, set the tracker variables
		    beingShown = false;
		    shown = true;
		});
            }
        }).mouseout(function () {
            // reset the timer if we get fired again - avoids double animations
            if (hideDelayTimer) clearTimeout(hideDelayTimer);

            // store the timer so that it can be cleared in the mouseover if required
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                popup.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    // once the animate is complete, set the tracker variables
                    shown = false;
                    // hide the popup entirely after the effect (opacity alone doesn't do the job)
                    popup.css('display', 'none');
                });
            }, hideDelay);
        });
    });
}

/***** XIGLA Banner Cache Disable *****/
jQuery(document).ready(function () {
	for (i=0; i< $('iframe').get().length; i++)
	{
		var src = $($('iframe').get(i)).attr('src');
	
		if (src!=null && src.indexOf('adman.hol.gr')>0)
		{
			if(src.indexOf('&amp;ts=')> 0)
			{
				src = src.substring(0, src.indexOf('&amp;ts='));
			}
			
			if(src.indexOf('&ts=')> 0)
			{
				src = src.substring(0, src.indexOf('&ts='));
			}

			var timestamp = new Date().getTime();
			$($('iframe').get(i)).attr('src', src + '&amp;ts=' + timestamp);
		}
	}
});

